summaryrefslogtreecommitdiff
path: root/jsonschema
diff options
context:
space:
mode:
authorJohn Anderson <sontek@gmail.com>2013-10-17 20:19:57 -0700
committerJohn Anderson <sontek@gmail.com>2013-10-17 20:19:57 -0700
commit1963981389d3a8e462af935f9e82759ff17654ae (patch)
tree377d48dd5c119bfa506a1878b0b53ff2a897381d /jsonschema
parentb6ede007ae7a6b57cf775776337d09261ddc3134 (diff)
downloadjsonschema-1963981389d3a8e462af935f9e82759ff17654ae.tar.gz
Clean up the output when an unknow type is found
Diffstat (limited to 'jsonschema')
-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