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

Improve schema validation error messages #140

Merged
merged 1 commit into from
Dec 20, 2024

Conversation

Pennycook
Copy link
Contributor

We previously decided to suppress jsonschema.exceptions.ValidationError messages because they provided a significant amount of context by default. By extracting the 'message' field, we can provide a helpful error message without also providing full context about the schema.

Related issues

Closes #67.

Proposed changes

  • Include the 'message' field in the ValueError raised by a validation failure.
  • Catch ValueError explicitly, since catching BaseException may hide other failures.
  • Fix a small bug in the validation docstring.

Before this change, any error in the .cbi/config file produced this error:

error: Configuration file failed validation

Now, it produces helpful errors:

[compiler."c++"]
options = ["-DASDF", 1]
~
error: Failed schema validation against schema/cbiconfig.schema: 1 is not of type 'string'
[compiler."c++"]
options = "-DASDF"
~                   
error: Failed schema validation against schema/cbiconfig.schema: '-DASDF' is not of type 'array'

@Pennycook Pennycook added the enhancement New feature or request label Dec 13, 2024
@Pennycook Pennycook added this to the 2.0.0 milestone Dec 13, 2024
We previously decided to suppress jsonschema.exceptions.ValidationError
messages because they provided a significant amount of context by default.
By extracting the 'message' field, we can provide a helpful error message
without also providing full context about the schema.

Signed-off-by: John Pennycook <[email protected]>
@Pennycook Pennycook force-pushed the schema-validation-errors branch from 36c2cb6 to 5d93902 Compare December 17, 2024 13:32
@Pennycook Pennycook merged commit 1b3c39c into intel:main Dec 20, 2024
3 checks passed
@Pennycook Pennycook deleted the schema-validation-errors branch December 20, 2024 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validation errors should be improved
2 participants