Skip to content

[WIP] feat!: useful validation errors #836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions cyclonedx/validation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from abc import ABC, abstractmethod
from collections.abc import Iterable
from typing import TYPE_CHECKING, Any, Literal, Optional, Protocol, Union, overload
from typing import TYPE_CHECKING, Literal, Optional, Protocol, Union, overload

from ..schema import OutputFormat

Expand All @@ -29,22 +29,20 @@


class ValidationError:
"""Validation failed with this specific error.
"""Validation failed with this specific error. """

Use :attr:`~data` to access the content.
"""

data: Any
"""Raw error data from one of the underlying validation methods."""
def __init__(self, message: str) -> None:
self._message = message

def __init__(self, data: Any) -> None:
self.data = data
@property
def message(self) -> str:
return self._message

def __repr__(self) -> str:
return repr(self.data)
return f'<{self.__class__.__qualname__} {self._message!r}>'

def __str__(self) -> str:
return str(self.data)
return self._message


class SchemabasedValidator(Protocol):
Expand Down
3 changes: 1 addition & 2 deletions cyclonedx/validation/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ class JsonValidationError(ValidationError):
@classmethod
def _make_from_jsve(cls, e: 'JsonSchemaValidationError') -> 'JsonValidationError':
"""⚠️ This is an internal API. It is not part of the public interface and may change without notice."""
# in preparation for https://github.com/CycloneDX/cyclonedx-python-lib/pull/836
return cls(e)
return cls(e.message) # TODO: shorten and more useful message? maybe there is a massage formatter?


class _BaseJsonValidator(BaseSchemabasedValidator, ABC):
Expand Down
3 changes: 1 addition & 2 deletions cyclonedx/validation/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ class XmlValidationError(ValidationError):
@classmethod
def _make_from_xle(cls, e: '_XmlLogEntry') -> 'XmlValidationError':
"""⚠️ This is an internal API. It is not part of the public interface and may change without notice."""
# in preparation for https://github.com/CycloneDX/cyclonedx-python-lib/pull/836
return cls(e)
return cls(e.message) # TODO: shorten and more useful message? maybe there is a massage formatter?


class _BaseXmlValidator(BaseSchemabasedValidator, ABC):
Expand Down
Loading