diff options
author | Glenn Maynard <glenn@zewt.org> | 2012-06-07 15:27:03 +0000 |
---|---|---|
committer | Glenn Maynard <glenn@zewt.org> | 2012-06-07 15:29:13 +0000 |
commit | 5dcb87b6f33beec067d3e4e35634bcb14cef282b (patch) | |
tree | bf04e61d472742ac3aef9d9d5cb2d3717e7c1519 | |
parent | ef233ae41387598978a19afd16f0296ad200bfdf (diff) | |
download | jsonschema-5dcb87b6f33beec067d3e4e35634bcb14cef282b.tar.gz |
Python3-compatible fix: don't discard exception backtraces.
This is important; it's next to impossible to debug problems when backtraces are lost.
-rw-r--r-- | jsonschema.py | 7 | ||||
-rw-r--r-- | raise_exception_2.py | 5 | ||||
-rw-r--r-- | raise_exception_3.py | 3 |
3 files changed, 14 insertions, 1 deletions
diff --git a/jsonschema.py b/jsonschema.py index 7994bf0..20c7659 100644 --- a/jsonschema.py +++ b/jsonschema.py @@ -22,6 +22,11 @@ import warnings PY3 = sys.version_info[0] >= 3 if PY3: + from raise_exception_3 import raise_exception_from +else: + from raise_exception_2 import raise_exception_from + +if PY3: basestring = unicode = str iteritems = operator.methodcaller("items") else: @@ -361,7 +366,7 @@ class Validator(object): try: self._meta_validator.validate(schema, self._version) except ValidationError as e: - raise SchemaError(str(e)) + raise_exception_from(SchemaError(str(e)), e) self._errors = [] self._validate(instance, schema) diff --git a/raise_exception_2.py b/raise_exception_2.py new file mode 100644 index 0000000..d8489ca --- /dev/null +++ b/raise_exception_2.py @@ -0,0 +1,5 @@ +# Raise an exception from another exception 2.x. +import sys +def raise_exception_from(exception, original_exception): + tb = sys.exc_info()[2] + raise exception, None, tb diff --git a/raise_exception_3.py b/raise_exception_3.py new file mode 100644 index 0000000..a74b1f6 --- /dev/null +++ b/raise_exception_3.py @@ -0,0 +1,3 @@ +# Raise an exception from another exception 3.x. +def raise_exception_from(exception, original_exception): + raise exception from original_exception |