summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2013-10-20 18:34:43 -0400
committerJulian Berman <Julian@GrayVines.com>2013-10-20 18:34:43 -0400
commit1397f0b0c9877ccb7e9174068268942493e71796 (patch)
treed15cffa776d3f77a4b7812ece1fc91f51dce6734
parent3906ee0e659a9aa6f5e2d506ebae81f89a06765e (diff)
parent4e6bf8051eef297d139302205c7fbdece32f49f0 (diff)
downloadjsonschema-1397f0b0c9877ccb7e9174068268942493e71796.tar.gz
Merge remote-tracking branch 'sontek/give_better_error_output'
* sontek/give_better_error_output: Better Py2/3 support Use pretty formatting Cleaned up output Clean up the output when an unknow type is found
-rw-r--r--jsonschema/exceptions.py26
-rw-r--r--jsonschema/validators.py2
2 files changed, 26 insertions, 2 deletions
diff --git a/jsonschema/exceptions.py b/jsonschema/exceptions.py
index f1d3e42..5d49410 100644
--- a/jsonschema/exceptions.py
+++ b/jsonschema/exceptions.py
@@ -93,7 +93,31 @@ class RefResolutionError(Exception):
class UnknownType(Exception):
- pass
+ def __init__(self, type, instance, schema):
+ self.type = type
+ self.instance = instance
+ self.schema = schema
+
+ def __str__(self):
+ return unicode(self).encode("utf-8")
+
+ def __unicode__(self):
+ pschema = pprint.pformat(self.schema, width=72)
+ pinstance = pprint.pformat(self.instance, width=72)
+ return textwrap.dedent("""
+ Unknown Type: %r, in schema:
+ %s
+
+ On instance:
+ %s
+ """.rstrip()
+ ) % (self.type,
+ _utils.indent(pschema),
+ _utils.indent(pinstance))
+
+ if PY3:
+ __str__ = __unicode__
+
class FormatError(Exception):
diff --git a/jsonschema/validators.py b/jsonschema/validators.py
index 22abf57..7044428 100644
--- a/jsonschema/validators.py
+++ b/jsonschema/validators.py
@@ -118,7 +118,7 @@ def create(meta_schema, validators=(), version=None, default_types=None): # noq
def is_type(self, instance, type):
if type not in self._types:
- raise UnknownType(type)
+ raise UnknownType(type, instance, self.schema)
pytypes = self._types[type]
# bool inherits from int, so ensure bools aren't reported as ints