summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChase Sterling <chase.sterling@gmail.com>2013-04-16 19:52:28 -0400
committerChase Sterling <chase.sterling@gmail.com>2013-04-16 20:14:16 -0400
commitd65af5a394041d70dc6f783d485e7294aaa4400e (patch)
treec85f15cf619456b88d6d078faf99b93617c6fdb1
parent2af34d8e3134d2c87c1a042b7e4ab3e5773d568b (diff)
downloadjsonschema-d65af5a394041d70dc6f783d485e7294aaa4400e.tar.gz
Update errors.rst for error printing change
Fix some other small errors for doctests
-rw-r--r--docs/errors.rst21
1 files changed, 17 insertions, 4 deletions
diff --git a/docs/errors.rst b/docs/errors.rst
index 1d8ab97..d7a33c5 100644
--- a/docs/errors.rst
+++ b/docs/errors.rst
@@ -95,9 +95,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
@@ -129,7 +129,7 @@ the schema each of these errors come from. In the case of sub-errors from the
>>> 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'
@@ -137,6 +137,19 @@ the schema each of these errors come from. In the case of sub-errors from the
[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
----------