Skip to content

[Validator] unclear error message #14

@hanson-hschang

Description

@hanson-hschang

Because of the for loop in the __post_init__, it shows the error message but does not show which validation function check that it fails. (I only know one of the methods in the list of self._validate_functions fails.)

class Validator(metaclass=ValidatorMeta):
def __init__(self) -> None:
self._errors: List[str] = []
self._validate_functions: List[Callable[[], bool]] = []
def __post_init__(self) -> None:
for validate in self._validate_functions:
assert validate(), self._errors

The current error message looks like something as the following:

  File "Signal-System/src/ss/utility/callback.py", line 61, in save
    filepath = FilePathValidator(filename, ".hdf5").get_filepath()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "Signal-System/src/ss/utility/assertion/validator.py", line 32, in __call__
    instance.__post_init__()
  File "Signal-System/src/ss/utility/assertion/validator.py", line 43, in __post_init__
    assert validate(), self._errors
           ^^^^^^^^^^
AssertionError: ['some error message']

It will be better to show more than just validate() has error.

Metadata

Metadata

Labels

enhancementNew feature or requestquestionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions