Twitch SDK (Internal)
Classes | Namespaces | Macros | Typedefs | Enumerations | Functions | Variables
errortypes.h File Reference
#include "twitchsdk/core/types/coretypes.h"
#include "twitchsdk/core/assertion.h"
#include <functional>
#include <vector>

Go to the source code of this file.

Classes

struct  ttv::EnumValue
 

Namespaces

 ttv
 JSON (JavaScript Object Notation).
 

Macros

#define CONSTRUCT_ERROR_ID_VALUE(MODULE_ID, ERROR_ID)   ( (1U << 31) | ( (MODULE_ID & kErrorModuleIdMask) << 16) | (ERROR_ID & kErrorIdMask) )
 
#define CONSTRUCT_WARNING_ID_VALUE(MODULE_ID, ERROR_ID)   ( (0U << 31) | ( (MODULE_ID & kErrorModuleIdMask) << 16) | (ERROR_ID & kErrorIdMask) )
 
#define GET_MODULE_ID(ec)   ( (ec >> 16) & kErrorModuleIdMask )
 
#define GET_ERROR_ID(ec)   ( ec & kErrorIdMask )
 
#define TTV_CORE_ERROR_IDS
 
#define USE_TTV_ERROR_ID(ec)   ec,
 
#define USE_TTV_WARNING_ID(ec)   ec,
 
#define USE_TTV_SUCCESS_ID(ec)   ec = 0,
 
#define BEGIN_WARNING_IDS(ec)   ec = CONSTRUCT_WARNING_ID_VALUE(TTV_MODULE_ID_TWITCH_CORE, (1 << 12)),
 
#define END_WARNING_IDS(ec)   ec,
 
#define BEGIN_ERROR_IDS(ec)   ec = CONSTRUCT_ERROR_ID_VALUE(TTV_MODULE_ID_TWITCH_CORE, 1),
 
#define END_ERROR_IDS(ec)   ec
 
#define TTV_SUCCEEDED(ec)   ( (ec & kErrorFlagMask) == 0 )
 
#define TTV_FAILED(ec)   ( (ec & kErrorFlagMask) != 0 )
 
#define ASSERT_ON_ERROR(ec)   { assert ( TTV_SUCCEEDED(ec) ); }
 
#define RETURN_CLIENT_ERROR(ec)   { return ec; }
 
#define TTV_RETURN_ON_NULL(ptr, ec)   { if ( (ptr) == nullptr) RETURN_CLIENT_ERROR(ec); }
 
#define TTV_RETURN_ON_NOT_NULL(ptr, ec)   { if ( (ptr) != nullptr) RETURN_CLIENT_ERROR(ec); }
 
#define TTV_RETURN_ON_EMPTY_STRING(str, ec)   { if (str == nullptr || str[0] == '\0') RETURN_CLIENT_ERROR(ec); }
 
#define TTV_RETURN_ON_EMPTY_STDSTRING(str, ec)   { if (str.size() == 0) RETURN_CLIENT_ERROR(ec); }
 
#define TTV_RETURN_ON_ERROR(err)   { if (TTV_FAILED(ec)) RETURN_CLIENT_ERROR(ec); }
 
#define TTV_RETURN_ON_DIFFERENT(a, b, ec)   { if ( (a) != (b) ) RETURN_CLIENT_ERROR(ec); }
 
#define TTV_RETURN_ON_SAME(a, b, ec)   { if ( (a) == (b) ) RETURN_CLIENT_ERROR(ec); }
 

Typedefs

typedef uint32_t TTV_ErrorCode
 
typedef const char *(* ttv::ErrorToStringFunction) (TTV_ErrorCode ec)
 
typedef void(* ttv::ErrorCodeValueFunction) (std::vector< EnumValue > &result)
 

Enumerations

enum  TTV_CoreErrorId { TTV_CORE_ERROR_IDS }
 

Functions

void ttv::RegisterErrorToStringFunction (ErrorToStringFunction func)
 
void ttv::UnregisterErrorToStringFunction (ErrorToStringFunction func)
 
void ttv::RegisterErrorCodeValueFunction (ErrorCodeValueFunction func)
 
void ttv::UnregisterErrorCodeValueFunction (ErrorCodeValueFunction func)
 
const char * ttv::ErrorToString (TTV_ErrorCode ec)
 
const char * ttv::CoreErrorToString (TTV_ErrorCode ec)
 
void ttv::GetCoreErrorCodeValues (std::vector< EnumValue > &result)
 
void ttv::GetAllErrorCodes (std::vector< EnumValue > &result)
 

Variables

const uint32_t TTV_MODULE_ID_TWITCH_CORE = 0
 
const uint32_t kErrorModuleIdMask = 0x7FFF
 
const uint32_t kErrorIdMask = 0xFFFF
 
const uint32_t kErrorFlagMask = 0x80000000
 

Macro Definition Documentation

◆ ASSERT_ON_ERROR

#define ASSERT_ON_ERROR (   ec)    { assert ( TTV_SUCCEEDED(ec) ); }

Asserts that the given error code passes TTV_SUCCEEDED(ec).

◆ BEGIN_ERROR_IDS

#define BEGIN_ERROR_IDS (   ec)    ec = CONSTRUCT_ERROR_ID_VALUE(TTV_MODULE_ID_TWITCH_CORE, 1),

◆ BEGIN_WARNING_IDS

#define BEGIN_WARNING_IDS (   ec)    ec = CONSTRUCT_WARNING_ID_VALUE(TTV_MODULE_ID_TWITCH_CORE, (1 << 12)),

◆ CONSTRUCT_ERROR_ID_VALUE

#define CONSTRUCT_ERROR_ID_VALUE (   MODULE_ID,
  ERROR_ID 
)    ( (1U << 31) | ( (MODULE_ID & kErrorModuleIdMask) << 16) | (ERROR_ID & kErrorIdMask) )

Creates an error code integer conforming to the format of TTV_ErrorCode.

◆ CONSTRUCT_WARNING_ID_VALUE

#define CONSTRUCT_WARNING_ID_VALUE (   MODULE_ID,
  ERROR_ID 
)    ( (0U << 31) | ( (MODULE_ID & kErrorModuleIdMask) << 16) | (ERROR_ID & kErrorIdMask) )

Creates an warning code integer conforming to the format of TTV_ErrorCode.

◆ END_ERROR_IDS

#define END_ERROR_IDS (   ec)    ec

◆ END_WARNING_IDS

#define END_WARNING_IDS (   ec)    ec,

◆ GET_ERROR_ID

#define GET_ERROR_ID (   ec)    ( ec & kErrorIdMask )

Extracts the error id from the given TTV_ErrorCode. It is appropriate to cast the id to the module-specific enumeration value.

◆ GET_MODULE_ID

#define GET_MODULE_ID (   ec)    ( (ec >> 16) & kErrorModuleIdMask )

Extracts the module id from the given TTV_ErrorCode.

◆ RETURN_CLIENT_ERROR

#define RETURN_CLIENT_ERROR (   ec)    { return ec; }

◆ TTV_CORE_ERROR_IDS

#define TTV_CORE_ERROR_IDS

◆ TTV_FAILED

#define TTV_FAILED (   ec)    ( (ec & kErrorFlagMask) != 0 )

Determines if the given code has the error bit set.

◆ TTV_RETURN_ON_DIFFERENT

#define TTV_RETURN_ON_DIFFERENT (   a,
  b,
  ec 
)    { if ( (a) != (b) ) RETURN_CLIENT_ERROR(ec); }

◆ TTV_RETURN_ON_EMPTY_STDSTRING

#define TTV_RETURN_ON_EMPTY_STDSTRING (   str,
  ec 
)    { if (str.size() == 0) RETURN_CLIENT_ERROR(ec); }

◆ TTV_RETURN_ON_EMPTY_STRING

#define TTV_RETURN_ON_EMPTY_STRING (   str,
  ec 
)    { if (str == nullptr || str[0] == '\0') RETURN_CLIENT_ERROR(ec); }

◆ TTV_RETURN_ON_ERROR

#define TTV_RETURN_ON_ERROR (   err)    { if (TTV_FAILED(ec)) RETURN_CLIENT_ERROR(ec); }

◆ TTV_RETURN_ON_NOT_NULL

#define TTV_RETURN_ON_NOT_NULL (   ptr,
  ec 
)    { if ( (ptr) != nullptr) RETURN_CLIENT_ERROR(ec); }

◆ TTV_RETURN_ON_NULL

#define TTV_RETURN_ON_NULL (   ptr,
  ec 
)    { if ( (ptr) == nullptr) RETURN_CLIENT_ERROR(ec); }

◆ TTV_RETURN_ON_SAME

#define TTV_RETURN_ON_SAME (   a,
  b,
  ec 
)    { if ( (a) == (b) ) RETURN_CLIENT_ERROR(ec); }

◆ TTV_SUCCEEDED

#define TTV_SUCCEEDED (   ec)    ( (ec & kErrorFlagMask) == 0 )

Determines if the given code does not have the error bit set. Pure success and warnings will pass this check.

◆ USE_TTV_ERROR_ID

#define USE_TTV_ERROR_ID (   ec)    ec,

◆ USE_TTV_SUCCESS_ID

#define USE_TTV_SUCCESS_ID (   ec)    ec = 0,

◆ USE_TTV_WARNING_ID

#define USE_TTV_WARNING_ID (   ec)    ec,

Typedef Documentation

◆ TTV_ErrorCode

typedef uint32_t TTV_ErrorCode

The generic error code type which represents error codes from all modules. It is constructed piecemeal as follows:

Error bit(1) | ModuleId(15) | ErrorId(16)

  • Error: A flag bit which indicates whether or not the value is an error. If 1, it is an error. If 0, it is a warning and TTV_SUCCEEDED(ec) will be true.
  • ModuleId: 15 bits to represent the module the code is defined in. This is not necessarily the source of the error. Each module has a unique id.
  • ErrorId: 16 bits to represent the unique error code within the module. Each module generally has an enumeration which defines them without the flag or module id.

Enumeration Type Documentation

◆ TTV_CoreErrorId

TTV_CoreErrorId - The error codes defined in core.

Enumerator
TTV_CORE_ERROR_IDS 

Variable Documentation

◆ kErrorFlagMask

const uint32_t kErrorFlagMask = 0x80000000

◆ kErrorIdMask

const uint32_t kErrorIdMask = 0xFFFF

◆ kErrorModuleIdMask

const uint32_t kErrorModuleIdMask = 0x7FFF

◆ TTV_MODULE_ID_TWITCH_CORE

const uint32_t TTV_MODULE_ID_TWITCH_CORE = 0

The unique module identifier for core.