diff --git a/cyclonedx/validation/__init__.py b/cyclonedx/validation/__init__.py index 7ff3b882..a7dd2d81 100644 --- a/cyclonedx/validation/__init__.py +++ b/cyclonedx/validation/__init__.py @@ -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 @@ -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): diff --git a/cyclonedx/validation/json.py b/cyclonedx/validation/json.py index 678a9d94..f228fb64 100644 --- a/cyclonedx/validation/json.py +++ b/cyclonedx/validation/json.py @@ -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): diff --git a/cyclonedx/validation/xml.py b/cyclonedx/validation/xml.py index 14f52808..f47b3c7a 100644 --- a/cyclonedx/validation/xml.py +++ b/cyclonedx/validation/xml.py @@ -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):