Skip to content

Commit eb0350d

Browse files
authored
Merge branch 'feat/validator_error_useful' into implement-fix-for-validation-error-messages
Signed-off-by: Saquib Saifee <saquibsaifee2@gmail.com>
2 parents 7b5f220 + add27ec commit eb0350d

1 file changed

Lines changed: 9 additions & 20 deletions

File tree

cyclonedx/validation/__init__.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from abc import ABC, abstractmethod
2020
from collections.abc import Iterable
21-
from typing import TYPE_CHECKING, Any, Literal, Optional, Protocol, Union, overload
21+
from typing import TYPE_CHECKING, Literal, Optional, Protocol, Union, overload
2222

2323
from ..schema import OutputFormat
2424

@@ -29,31 +29,20 @@
2929

3030

3131
class ValidationError:
32-
"""Validation failed with this specific error.
32+
"""Validation failed with this specific error. """
3333

34-
Use :attr:`~data` to access the content.
35-
"""
36-
37-
data: Any
38-
"""Raw error data from one of the underlying validation methods."""
39-
40-
message: str
41-
"""Human-readable error message suitable for end-user presentation."""
34+
def __init__(self, message: str) -> None:
35+
self._message = message
4236

43-
path: tuple[Union[str, int], ...]
44-
"""Path to the offending value if known."""
45-
46-
def __init__(self, data: Any, *, message: Optional[str] = None,
47-
path: Iterable[Union[str, int]] = ()) -> None:
48-
self.data = data
49-
self.message = str(data) if message is None else message
50-
self.path = tuple(path)
37+
@property
38+
def message(self) -> str:
39+
return self._message
5140

5241
def __repr__(self) -> str:
53-
return f'{self.__class__.__name__}(message={self.message!r}, path={self.path!r})'
42+
return f'<{self.__class__.__qualname__} {self._message!r}>'
5443

5544
def __str__(self) -> str:
56-
return self.message
45+
return self._message
5746

5847

5948
class SchemabasedValidator(Protocol):

0 commit comments

Comments
 (0)