feat: validators return specific error classes#840
Merged
Conversation
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferences |
Member
Author
|
this was released via https://github.com/CycloneDX/cyclonedx-python-lib/releases/tag/v10.4.0 |
2 tasks
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.
part of
in preparation for