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

jsonschema: print validation error location for default error reporter #489

Merged
merged 1 commit into from
Feb 21, 2024

Conversation

aldlfkahs
Copy link

Default error reporter in jsonschema prints only o.message() which only shows the reason. I think it is not enough. Users cannot know where the error occurs. Many other json schema libraries aim for human-comprehensible error messages.
So, how about print little bit more detail? I simply modified by adding o.instance_location() , referred from custom error reporter example in jsonschema doc.

@aldlfkahs
Copy link
Author

Additionally, I added fail_early parameter to validate(json, reporter) function for custom error reporter as well for personal use. If you also like this idea, I will make a PR for this too.

@danielaparker danielaparker merged commit 1e0fcda into danielaparker:master Feb 21, 2024
19 checks passed
@danielaparker
Copy link
Owner

Thanks for contributing. I've merged in this PR, however, we're currently doing a major rewrite of jsonschema on a branch, with the intention of supporting later versions starting with 2019-09, so it's probably better to postpone more jsonschema related PR's on main, until we merge in the new code. We definitely want to improve error messages and reporting, and reporting requirements added in the 2019-09 draft will also be supported in the draft 7 implementation. Any thoughts for further improvements are most welcome, and I'll look at your other suggestion.

@danielaparker
Copy link
Owner

Just FYI, regarding your second suggestion for fail_early, since version 0.175.0, the reporter passed to the json_schema<Json>::validate functions must return walk_result::advance or walk_result::abort, this gives the user control over early exit. (The legacy classes and functions, make_schema and json_validator, are not affected.)

@aldlfkahs
Copy link
Author

Great improvement! Thank you for sharing information of new release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants