Skip to content

Commit

Permalink
Be able to get the data on error
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Jun 3, 2021
1 parent 547fac6 commit 5dfb4eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions jsonschema_gentypes/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def main() -> None:
config = validate.load(args.config, json.loads(schema_data))
except validate.ValidationError as error:
LOG.error(error)
config = error.data
if not args.skip_config_errors:
sys.exit(1)

Expand Down
13 changes: 12 additions & 1 deletion jsonschema_gentypes/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ class ValidationError(Exception):
Exception thrown on validation issue.
"""

def __init__(self, message: str, data: Any):
"""
Construct.
Arguments:
message: The error message
data: The validated data
"""
super(message)
self.data = data


def load(
filename: str,
Expand All @@ -153,6 +164,6 @@ def load(
errors, data = validate(filename, data, schema, default)

if errors:
raise ValidationError("The config file is invalid:\n{}".format("\n".join(errors)))
raise ValidationError("The config file is invalid:\n{}".format("\n".join(errors)), data)

return data

0 comments on commit 5dfb4eb

Please sign in to comment.