diff options
author | Julian Berman <Julian@GrayVines.com> | 2013-04-19 18:00:58 -0400 |
---|---|---|
committer | Julian Berman <Julian@GrayVines.com> | 2013-04-19 18:00:58 -0400 |
commit | 76eb179ce371272db7b61006f20902b340030891 (patch) | |
tree | 8ee68a88db06d1687819243e15ebf1ca5beb92c7 /docs/errors.rst | |
parent | 314a753e7b388c0dcac5e92f71bfde7ae1637945 (diff) | |
parent | d65af5a394041d70dc6f783d485e7294aaa4400e (diff) | |
download | jsonschema-76eb179ce371272db7b61006f20902b340030891.tar.gz |
Merge remote-tracking branch 'gazpachoking/better_error_messages'
Diffstat (limited to 'docs/errors.rst')
-rw-r--r-- | docs/errors.rst | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/docs/errors.rst b/docs/errors.rst index 6d3a457..65bdbf4 100644 --- a/docs/errors.rst +++ b/docs/errors.rst @@ -96,9 +96,9 @@ The error messages in this situation are not very helpful on their own: >>> for error in errors: ... print(error.message) - The instance is not valid under any of the given schemas - The instance is not valid under any of the given schemas - The instance is not valid under any of the given schemas + {} is not valid under any of the given schemas + 3 is not valid under any of the given schemas + 'foo' is not valid under any of the given schemas If we look at :attr:`~ValidationError.path` on each of the errors, we can find out which elements in the instance correspond to each of the errors. In @@ -130,7 +130,7 @@ to the :attr:`~ValidationError.schema_path` of the parent error. >>> for error in errors: ... for suberror in sorted(error.context, key=lambda e: e.schema_path): - ... print(list(suberror.schema_path), suberror, sep=",") + ... print(list(suberror.schema_path), suberror.message, sep=", ") [0, 'type'], {} is not of type 'string' [1, 'type'], {} is not of type 'integer' [0, 'type'], 3 is not of type 'string' @@ -138,6 +138,19 @@ to the :attr:`~ValidationError.schema_path` of the parent error. [0, 'maxLength'], 'foo' is too long [1, 'type'], 'foo' is not of type 'integer' +The string representation of an error combines some of these attributes for +easier debugging. + +.. code-block:: python + + >>> print(errors[1]) + ValidationError: 3 is not valid under any of the given schemas + Failed validating 'anyOf' in schema['items']: + {'anyOf': [{'maxLength': 2, 'type': 'string'}, + {'minimum': 5, 'type': 'integer'}]} + On instance[1]: + 3 + <BLANKLINE> ErrorTrees ---------- |