COSC345-Eventures
Classes | Macros | Typedefs | Enumerations | Functions
RapidJSON error handling

Classes

struct  ParseResult
 Result of parsing (wraps ParseErrorCode) More...
 

Macros

#define RAPIDJSON_ERROR_CHARTYPE   char
 Character type of error messages. More...
 
#define RAPIDJSON_ERROR_STRING(x)   x
 Macro for converting string literal to RAPIDJSON_ERROR_CHARTYPE[]. More...
 
#define RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset)
 Macro to indicate a parse error. More...
 
#define RAPIDJSON_PARSE_ERROR(parseErrorCode, offset)
 (Internal) macro to indicate and handle a parse error. More...
 

Typedefs

typedef const RAPIDJSON_ERROR_CHARTYPE *(* GetParseErrorFunc) (ParseErrorCode)
 Function pointer type of GetParseError(). More...
 
typedef const RAPIDJSON_ERROR_CHARTYPE *(* GetValidateErrorFunc) (ValidateErrorCode)
 Function pointer type of GetValidateError(). More...
 
typedef const RAPIDJSON_ERROR_CHARTYPE *(* GetSchemaErrorFunc) (SchemaErrorCode)
 Function pointer type of GetSchemaError(). More...
 
typedef const RAPIDJSON_ERROR_CHARTYPE *(* GetPointerParseErrorFunc) (PointerParseErrorCode)
 Function pointer type of GetPointerParseError(). More...
 

Enumerations

enum  ParseErrorCode {
  kParseErrorNone = 0, kParseErrorDocumentEmpty, kParseErrorDocumentRootNotSingular, kParseErrorValueInvalid,
  kParseErrorObjectMissName, kParseErrorObjectMissColon, kParseErrorObjectMissCommaOrCurlyBracket, kParseErrorArrayMissCommaOrSquareBracket,
  kParseErrorStringUnicodeEscapeInvalidHex, kParseErrorStringUnicodeSurrogateInvalid, kParseErrorStringEscapeInvalid, kParseErrorStringMissQuotationMark,
  kParseErrorStringInvalidEncoding, kParseErrorNumberTooBig, kParseErrorNumberMissFraction, kParseErrorNumberMissExponent,
  kParseErrorTermination, kParseErrorUnspecificSyntaxError
}
 Error code of parsing. More...
 
enum  ValidateErrorCode {
  kValidateErrors = -1, kValidateErrorNone = 0, kValidateErrorMultipleOf, kValidateErrorMaximum,
  kValidateErrorExclusiveMaximum, kValidateErrorMinimum, kValidateErrorExclusiveMinimum, kValidateErrorMaxLength,
  kValidateErrorMinLength, kValidateErrorPattern, kValidateErrorMaxItems, kValidateErrorMinItems,
  kValidateErrorUniqueItems, kValidateErrorAdditionalItems, kValidateErrorMaxProperties, kValidateErrorMinProperties,
  kValidateErrorRequired, kValidateErrorAdditionalProperties, kValidateErrorPatternProperties, kValidateErrorDependencies,
  kValidateErrorEnum, kValidateErrorType, kValidateErrorOneOf, kValidateErrorOneOfMatch,
  kValidateErrorAllOf, kValidateErrorAnyOf, kValidateErrorNot, kValidateErrorReadOnly,
  kValidateErrorWriteOnly
}
 Error codes when validating. More...
 
enum  SchemaErrorCode {
  kSchemaErrorNone = 0, kSchemaErrorStartUnknown, kSchemaErrorRefPlainName, kSchemaErrorRefInvalid,
  kSchemaErrorRefPointerInvalid, kSchemaErrorRefUnknown, kSchemaErrorRefCyclical, kSchemaErrorRefNoRemoteProvider,
  kSchemaErrorRefNoRemoteSchema, kSchemaErrorRegexInvalid, kSchemaErrorSpecUnknown, kSchemaErrorSpecUnsupported,
  kSchemaErrorSpecIllegal, kSchemaErrorReadOnlyAndWriteOnly
}
 Error codes when validating. More...
 
enum  PointerParseErrorCode {
  kPointerParseErrorNone = 0, kPointerParseErrorTokenMustBeginWithSolidus, kPointerParseErrorInvalidEscape, kPointerParseErrorInvalidPercentEncoding,
  kPointerParseErrorCharacterMustPercentEncode
}
 Error code of JSON pointer parsing. More...
 

Functions

RAPIDJSON_NAMESPACE_BEGIN const RAPIDJSON_ERROR_CHARTYPEGetParseError_En (ParseErrorCode parseErrorCode)
 Maps error code of parsing into error message. More...
 
const RAPIDJSON_ERROR_CHARTYPEGetValidateError_En (ValidateErrorCode validateErrorCode)
 Maps error code of validation into error message. More...
 
const RAPIDJSON_ERROR_CHARTYPEGetSchemaError_En (SchemaErrorCode schemaErrorCode)
 Maps error code of schema document compilation into error message. More...
 
const RAPIDJSON_ERROR_CHARTYPEGetPointerParseError_En (PointerParseErrorCode pointerParseErrorCode)
 Maps error code of pointer parse into error message. More...
 

Detailed Description

Macro Definition Documentation

◆ RAPIDJSON_ERROR_CHARTYPE

#define RAPIDJSON_ERROR_CHARTYPE   char

Character type of error messages.

The default character type is char. On Windows, user can define this macro as TCHAR for supporting both unicode/non-unicode settings.

◆ RAPIDJSON_ERROR_STRING

#define RAPIDJSON_ERROR_STRING (   x)    x

Macro for converting string literal to RAPIDJSON_ERROR_CHARTYPE[].

By default this conversion macro does nothing. On Windows, user can define this macro as _T(x) for supporting both unicode/non-unicode settings.

◆ RAPIDJSON_PARSE_ERROR

#define RAPIDJSON_PARSE_ERROR (   parseErrorCode,
  offset 
)

(Internal) macro to indicate and handle a parse error.

Parameters
parseErrorCoderapidjson::ParseErrorCode of the error
offsetposition of the error in JSON input (size_t)

Invokes RAPIDJSON_PARSE_ERROR_NORETURN and stops the parsing.

See also
RAPIDJSON_PARSE_ERROR_NORETURN

◆ RAPIDJSON_PARSE_ERROR_NORETURN

#define RAPIDJSON_PARSE_ERROR_NORETURN (   parseErrorCode,
  offset 
)
Value:
RAPIDJSON_ASSERT(!HasParseError()); /* Error can only be assigned once */ \
SetParseError(parseErrorCode, offset); \
RAPIDJSON_MULTILINEMACRO_END
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:437

Macro to indicate a parse error.

Parameters
parseErrorCoderapidjson::ParseErrorCode of the error
offsetposition of the error in JSON input (size_t)

This macros can be used as a customization point for the internal error handling mechanism of RapidJSON.

A common usage model is to throw an exception instead of requiring the caller to explicitly check the rapidjson::GenericReader::Parse's return value:

#define RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode,offset) \
throw ParseException(parseErrorCode, #parseErrorCode, offset)
#include <stdexcept> // std::runtime_error
#include "rapidjson/error/error.h" // rapidjson::ParseResult
struct ParseException : std::runtime_error, rapidjson::ParseResult {
ParseException(rapidjson::ParseErrorCode code, const char* msg, size_t offset)
: std::runtime_error(msg), ParseResult(code, offset) {}
};
See also
RAPIDJSON_PARSE_ERROR, rapidjson::GenericReader::Parse

Typedef Documentation

◆ GetParseErrorFunc

typedef const RAPIDJSON_ERROR_CHARTYPE*(* GetParseErrorFunc) (ParseErrorCode)

Function pointer type of GetParseError().

This is the prototype for GetParseError_X(), where X is a locale. User can dynamically change locale in runtime, e.g.:

GetParseErrorFunc GetParseError = GetParseError_En; // or whatever
const RAPIDJSON_ERROR_CHARTYPE* s = GetParseError(document.GetParseErrorCode());

◆ GetPointerParseErrorFunc

typedef const RAPIDJSON_ERROR_CHARTYPE*(* GetPointerParseErrorFunc) (PointerParseErrorCode)

Function pointer type of GetPointerParseError().

This is the prototype for GetPointerParseError_X(), where X is a locale. User can dynamically change locale in runtime, e.g.:

GetPointerParseErrorFunc GetPointerParseError = GetPointerParseError_En; // or whatever
const RAPIDJSON_ERROR_CHARTYPE* s = GetPointerParseError(pointer.GetParseErrorCode());

◆ GetSchemaErrorFunc

typedef const RAPIDJSON_ERROR_CHARTYPE*(* GetSchemaErrorFunc) (SchemaErrorCode)

Function pointer type of GetSchemaError().

This is the prototype for GetSchemaError_X(), where X is a locale. User can dynamically change locale in runtime, e.g.:

GetSchemaErrorFunc GetSchemaError = GetSchemaError_En; // or whatever
const RAPIDJSON_ERROR_CHARTYPE* s = GetSchemaError(validator.GetInvalidSchemaCode());

◆ GetValidateErrorFunc

typedef const RAPIDJSON_ERROR_CHARTYPE*(* GetValidateErrorFunc) (ValidateErrorCode)

Function pointer type of GetValidateError().

This is the prototype for GetValidateError_X(), where X is a locale. User can dynamically change locale in runtime, e.g.:

GetValidateErrorFunc GetValidateError = GetValidateError_En; // or whatever
const RAPIDJSON_ERROR_CHARTYPE* s = GetValidateError(validator.GetInvalidSchemaCode());

Enumeration Type Documentation

◆ ParseErrorCode

Error code of parsing.

See also
GenericReader::Parse, GenericReader::GetParseErrorCode
Enumerator
kParseErrorNone 

No error.

kParseErrorDocumentEmpty 

The document is empty.

kParseErrorDocumentRootNotSingular 

The document root must not follow by other values.

kParseErrorValueInvalid 

Invalid value.

kParseErrorObjectMissName 

Missing a name for object member.

kParseErrorObjectMissColon 

Missing a colon after a name of object member.

kParseErrorObjectMissCommaOrCurlyBracket 

Missing a comma or '}' after an object member.

kParseErrorArrayMissCommaOrSquareBracket 

Missing a comma or ']' after an array element.

kParseErrorStringUnicodeEscapeInvalidHex 

Incorrect hex digit after \u escape in string.

kParseErrorStringUnicodeSurrogateInvalid 

The surrogate pair in string is invalid.

kParseErrorStringEscapeInvalid 

Invalid escape character in string.

kParseErrorStringMissQuotationMark 

Missing a closing quotation mark in string.

kParseErrorStringInvalidEncoding 

Invalid encoding in string.

kParseErrorNumberTooBig 

Number too big to be stored in double.

kParseErrorNumberMissFraction 

Miss fraction part in number.

kParseErrorNumberMissExponent 

Miss exponent in number.

kParseErrorTermination 

Parsing was terminated.

kParseErrorUnspecificSyntaxError 

Unspecific syntax error.

◆ PointerParseErrorCode

Error code of JSON pointer parsing.

See also
GenericPointer::GenericPointer, GenericPointer::GetParseErrorCode
Enumerator
kPointerParseErrorNone 

The parse is successful.

kPointerParseErrorTokenMustBeginWithSolidus 

A token must begin with a '/'.

kPointerParseErrorInvalidEscape 

Invalid escape.

kPointerParseErrorInvalidPercentEncoding 

Invalid percent encoding in URI fragment.

kPointerParseErrorCharacterMustPercentEncode 

A character must percent encoded in URI fragment.

◆ SchemaErrorCode

Error codes when validating.

See also
GenericSchemaValidator
Enumerator
kSchemaErrorNone 

No error.

kSchemaErrorStartUnknown 

Pointer to start of schema does not resolve to a location in the document.

kSchemaErrorRefPlainName 

$ref fragment must be a JSON pointer

kSchemaErrorRefInvalid 

$ref must not be an empty string

kSchemaErrorRefPointerInvalid 

$ref fragment is not a valid JSON pointer at offset

kSchemaErrorRefUnknown 

$ref does not resolve to a location in the target document

kSchemaErrorRefCyclical 

$ref is cyclical

kSchemaErrorRefNoRemoteProvider 

$ref is remote but there is no remote provider

kSchemaErrorRefNoRemoteSchema 

$ref is remote but the remote provider did not return a schema

kSchemaErrorRegexInvalid 

Invalid regular expression in 'pattern' or 'patternProperties'.

kSchemaErrorSpecUnknown 

JSON schema draft or OpenAPI version is not recognized.

kSchemaErrorSpecUnsupported 

JSON schema draft or OpenAPI version is not supported.

kSchemaErrorSpecIllegal 

Both JSON schema draft and OpenAPI version found in document.

kSchemaErrorReadOnlyAndWriteOnly 

Property must not be both 'readOnly' and 'writeOnly'.

◆ ValidateErrorCode

Error codes when validating.

See also
GenericSchemaValidator
Enumerator
kValidateErrors 

Top level error code when kValidateContinueOnErrorsFlag set.

kValidateErrorNone 

No error.

kValidateErrorMultipleOf 

Number is not a multiple of the 'multipleOf' value.

kValidateErrorMaximum 

Number is greater than the 'maximum' value.

kValidateErrorExclusiveMaximum 

Number is greater than or equal to the 'maximum' value.

kValidateErrorMinimum 

Number is less than the 'minimum' value.

kValidateErrorExclusiveMinimum 

Number is less than or equal to the 'minimum' value.

kValidateErrorMaxLength 

String is longer than the 'maxLength' value.

kValidateErrorMinLength 

String is longer than the 'maxLength' value.

kValidateErrorPattern 

String does not match the 'pattern' regular expression.

kValidateErrorMaxItems 

Array is longer than the 'maxItems' value.

kValidateErrorMinItems 

Array is shorter than the 'minItems' value.

kValidateErrorUniqueItems 

Array has duplicate items but 'uniqueItems' is true.

kValidateErrorAdditionalItems 

Array has additional items that are not allowed by the schema.

kValidateErrorMaxProperties 

Object has more members than 'maxProperties' value.

kValidateErrorMinProperties 

Object has less members than 'minProperties' value.

kValidateErrorRequired 

Object is missing one or more members required by the schema.

kValidateErrorAdditionalProperties 

Object has additional members that are not allowed by the schema.

kValidateErrorPatternProperties 

See other errors.

kValidateErrorDependencies 

Object has missing property or schema dependencies.

kValidateErrorEnum 

Property has a value that is not one of its allowed enumerated values.

kValidateErrorType 

Property has a type that is not allowed by the schema.

kValidateErrorOneOf 

Property did not match any of the sub-schemas specified by 'oneOf'.

kValidateErrorOneOfMatch 

Property matched more than one of the sub-schemas specified by 'oneOf'.

kValidateErrorAllOf 

Property did not match all of the sub-schemas specified by 'allOf'.

kValidateErrorAnyOf 

Property did not match any of the sub-schemas specified by 'anyOf'.

kValidateErrorNot 

Property matched the sub-schema specified by 'not'.

kValidateErrorReadOnly 

Property is read-only but has been provided when validation is for writing.

kValidateErrorWriteOnly 

Property is write-only but has been provided when validation is for reading.

Function Documentation

◆ GetParseError_En()

RAPIDJSON_NAMESPACE_BEGIN const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En ( ParseErrorCode  parseErrorCode)
inline

Maps error code of parsing into error message.

Parameters
parseErrorCodeError code obtained in parsing.
Returns
the error message.
Note
User can make a copy of this function for localization. Using switch-case is safer for future modification of error codes.

◆ GetPointerParseError_En()

const RAPIDJSON_ERROR_CHARTYPE* GetPointerParseError_En ( PointerParseErrorCode  pointerParseErrorCode)
inline

Maps error code of pointer parse into error message.

Parameters
pointerParseErrorCodeError code obtained from pointer parse.
Returns
the error message.
Note
User can make a copy of this function for localization. Using switch-case is safer for future modification of error codes.

◆ GetSchemaError_En()

const RAPIDJSON_ERROR_CHARTYPE* GetSchemaError_En ( SchemaErrorCode  schemaErrorCode)
inline

Maps error code of schema document compilation into error message.

Parameters
schemaErrorCodeError code obtained from compiling the schema document.
Returns
the error message.
Note
User can make a copy of this function for localization. Using switch-case is safer for future modification of error codes.

◆ GetValidateError_En()

const RAPIDJSON_ERROR_CHARTYPE* GetValidateError_En ( ValidateErrorCode  validateErrorCode)
inline

Maps error code of validation into error message.

Parameters
validateErrorCodeError code obtained from validator.
Returns
the error message.
Note
User can make a copy of this function for localization. Using switch-case is safer for future modification of error codes.