Skip to content

Commit d65af5a

Browse files
committed
Update errors.rst for error printing change
Fix some other small errors for doctests
1 parent 2af34d8 commit d65af5a

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

docs/errors.rst

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ The error messages in this situation are not very helpful on their own:
9595
9696
>>> for error in errors:
9797
... print(error.message)
98-
The instance is not valid under any of the given schemas
99-
The instance is not valid under any of the given schemas
100-
The instance is not valid under any of the given schemas
98+
{} is not valid under any of the given schemas
99+
3 is not valid under any of the given schemas
100+
'foo' is not valid under any of the given schemas
101101
102102
If we look at :attr:`ValidationError.path` on each of the errors, we can find
103103
out which elements in the instance correspond to each of the errors. In
@@ -129,14 +129,27 @@ the schema each of these errors come from. In the case of sub-errors from the
129129
130130
>>> for error in errors:
131131
... for suberror in sorted(error.context, key=lambda e: e.schema_path):
132-
... print(list(suberror.schema_path), suberror, sep=",")
132+
... print(list(suberror.schema_path), suberror.message, sep=", ")
133133
[0, 'type'], {} is not of type 'string'
134134
[1, 'type'], {} is not of type 'integer'
135135
[0, 'type'], 3 is not of type 'string'
136136
[1, 'minimum'], 3.0 is less than the minimum of 5
137137
[0, 'maxLength'], 'foo' is too long
138138
[1, 'type'], 'foo' is not of type 'integer'
139139
140+
The string representation of an error combines some of these attributes for
141+
easier debugging.
142+
143+
.. code-block:: python
144+
145+
>>> print(errors[1])
146+
ValidationError: 3 is not valid under any of the given schemas
147+
Failed validating 'anyOf' in schema['items']:
148+
{'anyOf': [{'maxLength': 2, 'type': 'string'},
149+
{'minimum': 5, 'type': 'integer'}]}
150+
On instance[1]:
151+
3
152+
<BLANKLINE>
140153
141154
ErrorTrees
142155
----------

0 commit comments

Comments
 (0)