Skip to content

Commit d00327b

Browse files
committed
Start some work on more detailed messages of errors
1 parent cc09caf commit d00327b

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

jsonschema.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import json
1919
import numbers
2020
import operator
21+
import pprint
2122
import re
2223
import socket
2324
import sys
@@ -108,7 +109,31 @@ def __str__(self):
108109
return unicode(self).encode("utf-8")
109110

110111
def __unicode__(self):
111-
return self.message
112+
schema_path = ""
113+
if len(self.schema_path) > 1:
114+
schema_path = (
115+
"[%s]" % "][".join(
116+
map(repr, list(self.schema_path)[:-1])
117+
)
118+
)
119+
path = ""
120+
if self.path:
121+
path = "[%s]" % "][".join(map(repr, self.path))
122+
pschema = pprint.pformat(self.schema, width=72)
123+
pinstance = pprint.pformat(self.instance, width=72)
124+
return textwrap.dedent("""\
125+
%s: %s
126+
Failed validating '%s' in schema%s:
127+
%s
128+
On instance%s:
129+
%s
130+
""") % (
131+
self.__class__.__name__, self.message,
132+
self.validator, schema_path,
133+
textwrap.indent(pschema, " " * 8),
134+
path,
135+
textwrap.indent(pinstance, " " * 8)
136+
)
112137

113138
if PY3:
114139
__str__ = __unicode__

0 commit comments

Comments
 (0)