diff --git a/docs/references.rst b/docs/references.rst index 2664e9b..9f24299 100644 --- a/docs/references.rst +++ b/docs/references.rst @@ -7,3 +7,7 @@ Resolving JSON References .. autoclass:: RefResolver :members: + +.. autoexception:: RefResolutionError + + A JSON reference failed to resolve. diff --git a/docs/validate.rst b/docs/validate.rst index 4db45b4..48ee032 100644 --- a/docs/validate.rst +++ b/docs/validate.rst @@ -94,6 +94,7 @@ adhere to. :type type: str :rtype: bool + :raises: :exc:`UnknownType` if ``type`` is not a known type. The special type ``"any"`` is valid for any given instance. diff --git a/jsonschema.py b/jsonschema.py index bced6e1..6e8fe05 100644 --- a/jsonschema.py +++ b/jsonschema.py @@ -54,6 +54,23 @@ FLOAT_TOLERANCE = 10 ** -15 validators = {} +class _Error(Exception): + def __init__(self, message, validator=None, path=()): + super(_Error, self).__init__(message, validator, path) + self.message = message + self.path = list(path) + self.validator = validator + + def __str__(self): + return self.message + + +class SchemaError(_Error): pass +class ValidationError(_Error): pass +class RefResolutionError(Exception): pass +class UnknownType(Exception): pass + + def validates(version): """ Register the decorated validator for a ``version`` of the specification. @@ -72,31 +89,6 @@ def validates(version): return _validates -class UnknownType(Exception): - """ - An attempt was made to check if an instance was of an unknown type. - - """ - - -class RefResolutionError(Exception): - """ - A JSON reference failed to resolve. - - """ - - -class SchemaError(Exception): - def __init__(self, message, validator=None, path=()): - super(SchemaError, self).__init__(message, validator, path) - self.message = message - self.path = list(path) - self.validator = validator - - def __str__(self): - return self.message - - class ValidationError(Exception): def __init__(self, message, validator=None, path=()): # Any validator that recurses (e.g. properties and items) must append