summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jsonschema/exceptions.py23
-rw-r--r--jsonschema/validators.py2
2 files changed, 23 insertions, 2 deletions
diff --git a/jsonschema/exceptions.py b/jsonschema/exceptions.py
index f1d3e42..b24478a 100644
--- a/jsonschema/exceptions.py
+++ b/jsonschema/exceptions.py
@@ -93,7 +93,28 @@ class RefResolutionError(Exception):
class UnknownType(Exception):
- pass
+ def __init__(self, type, instance, schema):
+ self.type = type
+ self.instance = instance
+ self.schema = schema
+ self.msg = "OMGZ"
+
+ def __str__(self):
+ return self.__unicode__()
+
+ def __unicode__(self):
+ pschema = pprint.pformat(self.schema, width=72)
+ pinstance = pprint.pformat(self.instance, width=72)
+ return textwrap.dedent("""
+ unknown type %s, in schema:
+ %r
+
+ On instance:
+ %s
+ """.rstrip()
+ ) % (self.type, self.schema, self.instance)
+
+
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