Skip to content

feat: validators return specific error classes - #840

Merged
jkowalleck merged 2 commits into
mainfrom
feat/validators_return_specific_error_classes
Jul 3, 2025
Merged

feat: validators return specific error classes#840
jkowalleck merged 2 commits into
mainfrom
feat/validators_return_specific_error_classes

Conversation

@jkowalleck

@jkowalleckjkowalleck commented Jul 3, 2025

Copy link
Copy Markdown
Member

Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
@jkowalleck
jkowalleck requested a review from a team as a code ownerJuly 3, 2025 10:12
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
@jkowalleckjkowalleck added the enhancement New feature or request label Jul 3, 2025
@codacy-production

Copy link
Copy Markdown

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variationDiff coverage
+0.01%100.00% (target: 80.00%)
Coverage variation details
Coverable linesCovered linesCoverage
Common ancestor commit (34a11aa)5628526793.59%
Head commit (0b765bc)5636 (+8)5275 (+8)93.59% (+0.01%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable linesCovered linesDiff coverage
Pull request (#840)1717100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settingsChange summary preferences

@jkowalleck
jkowalleck merged commit 23a0f72 into mainJul 3, 2025
@jkowalleck
jkowalleck deleted the feat/validators_return_specific_error_classes branch July 3, 2025 10:24
@jkowalleck

Copy link
Copy Markdown
MemberAuthor

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
ClosesCycloneDX#827
Signed-off-by: Saquib Saifee <saquibsaifee2@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancementNew feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@jkowalleck