diff options
author | Brian Waldon <bcwaldon@gmail.com> | 2012-11-19 13:59:22 -0800 |
---|---|---|
committer | Brian Waldon <bcwaldon@gmail.com> | 2012-11-19 13:59:22 -0800 |
commit | 40abb76f3bfa45501b1c085577d6aa0dfb9f6c4d (patch) | |
tree | 52a492525a5a23fb31fe72fd026e62af3215377b | |
parent | cd69c88a692e1ffbdcc5ceafd2dab45ec20d38d5 (diff) | |
download | warlock-40abb76f3bfa45501b1c085577d6aa0dfb9f6c4d.tar.gz |
Add helful text to Exceptions
Fixes issue #2
-rw-r--r-- | warlock/core.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/warlock/core.py b/warlock/core.py index ad3f3bd..da662ec 100644 --- a/warlock/core.py +++ b/warlock/core.py @@ -24,8 +24,8 @@ def model_factory(schema): """Apply a JSON schema to an object""" try: jsonschema.validate(obj, schema) - except jsonschema.ValidationError: - raise ValidationError() + except jsonschema.ValidationError as exc: + raise ValidationError(str(exc)) class Model(dict): """Self-validating model for arbitrary objects""" @@ -37,8 +37,8 @@ def model_factory(schema): self.__dict__['validator'] = validator try: self.validator(d) - except ValidationError: - raise ValueError() + except ValidationError as exc: + raise ValueError(str(exc)) else: dict.__init__(self, d) @@ -56,7 +56,8 @@ def model_factory(schema): try: self.validator(mutation) except ValidationError: - raise InvalidOperation() + msg = "Unable to set '%s' to '%s'" % (key, value) + raise InvalidOperation(msg) dict.__setitem__(self, key, value) @@ -86,8 +87,8 @@ def model_factory(schema): mutation.update(other) try: self.validator(mutation) - except ValidationError: - raise InvalidOperation() + except ValidationError as exc: + raise InvalidOperation(str(exc)) dict.update(self, other) def iteritems(self): |