Validation errors are hard to present safely to the user (missing abstraction)
@jkowalleck arbeitet bereits daran.
Seit 01.7.2025.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Beginnen Sie mit cyclonedx/validation/init.py sowie den im Issue referenzierten Einstiegspunkten validation/json.py und validation/xml.py und reproduzieren Sie anschließend die Beispiele unter Verwendung der aufgeführten schemaTestData-Dateien. Als abgeschlossen gilt die Arbeit, wenn die JSON- und XML-Validierung über eine gemeinsame Abstraktion einen stabilen Pfad und eine sichere Meldung bereitstellen und gleichzeitig den unverarbeiteten zugrunde liegenden Fehler in data beibehalten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
https://cyclonedx-python-library.readthedocs.io/en/v10.2.0/autoapi/cyclonedx/validation/
We are using both JSON and XML inputs, and when something is wrong with the input, it is not easy to get the location of the problem or even what is wrong can be hidden in a multi-MB message.
One of the problem is, that the underlying libraries make it hard:
jsonschemaincludes all the input (instance) in the error message, which in the SBOM case can be quite big, producing the above mentioned multi-MB message (thisuniqueItemscheck can fail on e.g. thedependencies):yield ValidationError(f"{instance!r} has non-unique elements")- in the xml case, somehow the easiest solution was to get the error from the logs: https://github.com/CycloneDX/cyclonedx-python-lib/blob/1a932a2ab00efb029c7b685cba7d9e5af3b7ea19/cyclonedx/validation/xml.py#L71
The other problem is, that CycloneDX makes no attempt at transforming these different object types into something sensible and type-safe for users, the raw objects are simply leaked through the interface as is in https://github.com/CycloneDX/cyclonedx-python-lib/blob/1a932a2ab00efb029c7b685cba7d9e5af3b7ea19/cyclonedx/validation/__init__.py#L36
Code samples triggering long messages:
from cyclonedx.validation.json import JsonStrictValidator
from cyclonedx.schema import SchemaVersion
test_data_file = "tests/_data/schemaTestData/1.2/invalid-license-id-1.2.json"
schema_version = SchemaVersion.V1_2
validator = JsonStrictValidator(schema_version)
with open(test_data_file) as tdfh:
test_data = tdfh.read()
validation_error = validator.validate_str(test_data)
print(str(validation_error))
This message is 35508 characters long - 767 lines!
from cyclonedx.validation.xml import XmlValidator
from cyclonedx.schema import SchemaVersion
test_data_file = "tests/_data/schemaTestData/1.1/invalid-license-id-1.1.xml"
schema_version = SchemaVersion.V1_1
validator = XmlValidator(schema_version)
with open(test_data_file) as tdfh:
test_data = tdfh.read()
validation_error = validator.validate_str(test_data)
print(str(validation_error))
This message is 12423 characters long - 1 line.
I would expect the errors returned/raised by CycloneDX something like below:
class ValidationError:
# abstract class
data: Any
"raw problem, for debugging"
path: str
message: str
class XmlValidationError(ValidationError):
# this subclass knows what data is
@property
def path(self):
return self.data.path
@property
def message(self):
return self.data.message
class JsonValidationError(ValidationError):
# this subclass knows what data is
@property
def path(self):
return self.data.json_path
@property
def message(self):
# ensures the error is transformed to something sensible
# resolving a problem caused by using jsonscheme for CycloneDX users
instance = repr(self.data.instance)
return self.data.message.replace(instance, shortened(instance))
# where shortened(long_text) ~ 'first n ... last n', that is the middle of the string replaced
# this would still add some context, but it will be safe to display
These would provide a stable abstraction over generally useful validation error properties, and also hide implementation details from users, like third party objects lxml.etree._LogEntry and jsonschema.exceptions.ValidationError. The above proposal is also backward compatible, keeping data intact, if someone depends on it.
- Vorherrschende Sprache
- Python
- Sterne
- 117
- Forks
- 67
- Ø Merge
- 3 T. 9 Std.
- Gemergte PRs (30 T.)
- 4
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus CycloneDX/cyclonedx-python-lib
-
Support Python 3.15Evtl. vergeben @jkowalleck hat das vor 3 Tagen übernommen. Offenenhancement
CycloneDX/cyclonedx-python-lib#1056 · 1 zugewiesene Person ·
-
[PERF] Quadratic (O(N^2)) serialization time for large BOMs — `Bom.validate()` → `register_dependency()` linear scanEvtl. vergeben @inspired-geek hat das vor 124 Tagen übernommen. Offenperformance
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 36/100
CycloneDX/cyclonedx-python-lib#1006 · 2 Kommentare ·
-
tests: test all model enumsEvtl. wieder frei @jkowalleck hat das vor 139 Tagen übernommen, und es ist kein Pull Request offen. OffenQA
CycloneDX/cyclonedx-python-lib#991 · 1 zugewiesene Person ·
-
feat(deps)!: make all de/serialization libraries optionalEvtl. wieder frei @Simoh23999 hat das vor 87 Tagen übernommen, und es ist kein Pull Request offen. Offenbreaking change dependencies
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
CycloneDX/cyclonedx-python-lib#979 · 2 Kommentare ·
-
feat: Add support for Component signatureEvtl. vergeben @wiebe-vandendriessche hat das vor 138 Tagen übernommen. Offenenhancement help wanted schema 1.4
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 58/100
CycloneDX/cyclonedx-python-lib#978 · 4 Kommentare ·
Alle Issues in CycloneDX/cyclonedx-python-lib
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
GoogleCloudPlatform/gce-rescue#195 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
Maintainer antworten meist innerhalb von 1 Tag
-
intake mcp-intake needs-ac needs-human-review priority:medium
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
Ikalus1988/MisakaNet#3848 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 75/100
521xueweihan/HelloGitHub#4105 ·
-
bug size:XS
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
Maintainer antworten meist innerhalb von 1 Tag