Skip to content

Schema exception handling #647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions jsonschema/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ def iter_errors(self, instance, _schema=None):

errors = validator(self, v, instance, _schema) or ()
for error in errors:
# set details if not already set by the called fn
error._set(
validator=k,
validator_value=v,
Expand All @@ -349,8 +348,15 @@ def descend(self, instance, schema, path=None, schema_path=None):
yield error

def validate(self, *args, **kwargs):
for error in self.iter_errors(*args, **kwargs):
raise error
errors = self.iter_errors(*args, **kwargs)
matched_errors = exceptions.best_match(errors)
error_dict = {}
error_message = None
if matched_errors:
error_dict['key'] = list(matched_errors.path)[-1]
error_dict['message'] = matched_errors.message
error_message = "Schema Error! " + str(error_dict)
return error_message

def is_type(self, instance, type):
try:
Expand Down