summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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