Skip to content
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

Be able to get the data on error #25

Merged
merged 1 commit into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
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
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and ? you don't do anything with these data ? It's just to be able to debug ?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set the config that's used at line 54 and next, the skip_config_errors was just not working before...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, sorry

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) -> None:
"""
Construct.

Arguments:
message: The error message
data: The validated data
"""
super().__init__(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