From 7b9a861db18c1aa1dbebcfc514ffa719eec97eb0 Mon Sep 17 00:00:00 2001 From: tangkong Date: Mon, 26 Feb 2024 16:09:01 -0800 Subject: [PATCH] MNT: validators can only throw ValidationError --- superscore/model.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/superscore/model.py b/superscore/model.py index e03f9d1..eeae4c4 100644 --- a/superscore/model.py +++ b/superscore/model.py @@ -12,7 +12,7 @@ get_type_hints) from uuid import UUID, uuid4 -from apischema.validation import validate, validator +from apischema.validation import ValidationError, validate, validator from superscore.type_hints import AnyEpicsType @@ -66,7 +66,7 @@ def validate_field(self, field_name: str, hint: Any) -> None: Raises ------ - TypeError + ValidationError if a type mismatch is found """ field_value = getattr(self, field_name) @@ -93,15 +93,15 @@ def validate_field(self, field_name: str, hint: Any) -> None: return elif (origin is None): if not isinstance(field_value, hint): - raise TypeError('improper type found in field') + raise ValidationError('improper type found in field') elif (origin is Union) and (UUID in get_args(hint)): # Case of interest. A hint of Union[UUID, SomeType] if is_list: list_comp = (isinstance(it, get_args(hint)) for it in field_value) if not all(list_comp): - raise TypeError('improper type in list-field') + raise ValidationError('improper type in list-field') elif not isinstance(field_value, get_args(hint)): - raise TypeError('improper type found in field') + raise ValidationError('improper type found in field') @dataclass