Validation errors are hard to present safely to the user (missing abstraction)
@jkowalleck já está trabalhando nisso.
Desde 1/7/2025.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 35/100
Direção de pesquisa
Comece por cyclonedx/validation/init.py e pelos pontos de entrada validation/json.py e validation/xml.py referenciados na issue, depois reproduza os exemplos usando os arquivos schemaTestData listados. Está concluído quando a validação JSON e XML expuser um caminho estável e uma mensagem segura por meio de uma abstração comum, mantendo ao mesmo tempo o erro subjacente bruto em data.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- Python
- Estrelas
- 117
- Forks
- 67
- Merge médio
- 3d 9h
- PRs com merge (30d)
- 4
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de CycloneDX/cyclonedx-python-lib
-
Support Python 3.15Talvez já em andamento @jkowalleck assumiu há 7 dias. Abertaenhancement
CycloneDX/cyclonedx-python-lib#1056 · 1 responsável ·
-
[PERF] Quadratic (O(N^2)) serialization time for large BOMs — `Bom.validate()` → `register_dependency()` linear scanTalvez já em andamento @inspired-geek assumiu há 127 dias. Abertaperformance
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 36/100
CycloneDX/cyclonedx-python-lib#1006 · 2 comentários ·
-
tests: test all model enumsTalvez livre de novo @jkowalleck assumiu há 143 dias e não há nenhum pull request aberto. AbertaQA
CycloneDX/cyclonedx-python-lib#991 · 1 responsável ·
-
feat(deps)!: make all de/serialization libraries optionalTalvez livre de novo @Simoh23999 assumiu há 90 dias e não há nenhum pull request aberto. Abertabreaking change dependencies
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
CycloneDX/cyclonedx-python-lib#979 · 2 comentários ·
-
feat: Add support for Component signatureTalvez já em andamento @wiebe-vandendriessche assumiu há 141 dias. Abertaenhancement help wanted schema 1.4
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 58/100
CycloneDX/cyclonedx-python-lib#978 · 4 comentários ·
Todas as issues de CycloneDX/cyclonedx-python-lib
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
microsoft/agent-lightning#661 ·
Mantenedores costumam responder em até 2 dias
-
area/profiles comp/cli P3 type/feature
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
NousResearch/hermes-agent#146372 ·
Mantenedores costumam responder em até 1 dia
-
[BUG] OpenAI-compatible embedding model alias breaks embedder constructionTalvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
Mantenedores costumam responder em até 1 dia
-
[oblt-aw][autodoc] Document obs-aw-automerge contract and fix automerge doc inconsistenciesTalvez já em andamento @github-actions assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
Mantenedores costumam responder em até 1 dia
-
GeoSeries scale and skew tests fail with pytest 9.2.0Talvez já em andamento @jiayuasu assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
Mantenedores costumam responder em até 1 dia