[WIP] feat!: useful validation errors#836
Draft
jkowalleck wants to merge 3 commits into
Draft
Conversation
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Member
Author
|
currently work in progress. |
jkowalleck
added a commit
that referenced
this pull request
Jul 3, 2025
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
|
@jkowalleck we already try to do this within our tool. Maybe there are some synergies possible, as we are also still facing sometimes nonsensical error message for nested dicts. |
saquibsaifee
added a commit
to saquibsaifee/cyclonedx-python-lib
that referenced
this pull request
Jul 14, 2026
Implements the planned improvement from PR CycloneDX#836 by the maintainer. - ValidationError gains structured fields: message (str), path (tuple), and data (raw backend object) — replacing the bare data-only shape - JsonValidationError._make_from_jsve recurses into nested jsonschema context errors to surface the most specific leaf failure for oneOf/anyOf - XmlValidationError._make_from_xle maps lxml _LogEntry.message and path - __repr__ and __str__ now emit the human-readable message field Closes CycloneDX#827
2 tasks
saquibsaifee
added a commit
to saquibsaifee/cyclonedx-python-lib
that referenced
this pull request
Jul 14, 2026
Implements the planned improvement from PR CycloneDX#836 by the maintainer. - ValidationError gains structured fields: message (str), path (tuple), and data (raw backend object) — replacing the bare data-only shape - JsonValidationError._make_from_jsve recurses into nested jsonschema context errors to surface the most specific leaf failure for oneOf/anyOf - XmlValidationError._make_from_xle maps lxml _LogEntry.message and path - __repr__ and __str__ now emit the human-readable message field Closes CycloneDX#827 Signed-off-by: Saquib Saifee <saquibsaifee2@gmail.com>
saquibsaifee
added a commit
to saquibsaifee/cyclonedx-python-lib
that referenced
this pull request
Jul 14, 2026
PRs already in main that this builds on: - CycloneDX#834 (merged): added all_errors support and JsonValidationError / XmlValidationError subclass stubs - CycloneDX#840 (merged): refined the subclass stubs further - CycloneDX#836 (WIP by maintainer): placeholder for this exact work Changes ------- ValidationError (__init__.py) - Add message (str): human-readable, bounded error message - Add path (tuple[str|int, ...]): location of the offending value - Keep data (Any): raw backend object, unchanged for backward compat - __str__ now returns message; __repr__ is structured JsonValidationError (json.py) - __get_most_relevant_jsve: recurse into nested jsonschema context errors to surface the deepest leaf failure for oneOf/anyOf checks, instead of emitting the generic parent message - _shorten_message: (1) replace a bloated repr(instance) with a head...tail summary for uniqueItems/large-document failures, then (2) hard-cap the whole message at 256 chars + ellipsis XmlValidationError (xml.py) - _shorten_xml_message: hard-cap lxml _LogEntry.message at 256 chars, preventing the full SPDX enumeration set from appearing verbatim - path populated from _LogEntry.path (XPath location string) Before vs after (invalid-license-id test files from issue CycloneDX#827) JSON str(error): 111,672 chars -> 257 chars XML str(error): 13,430 chars -> 257 chars error.message: AttributeError -> bounded str error.path: AttributeError -> structured tuple Tests (test_validation_json.py, test_validation_xml.py) - Assert error is the correct subtype (JsonValidationError / XmlValidationError) - Assert .message is a str and .path is a tuple - Assert len(message) <= 257 across every invalid test file for every schema version Closes CycloneDX#827 Signed-off-by: Saquib Saifee <saquibsaifee2@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
goal: have useful messages on validation errors.
TODO