Skip to content

erdantic.exceptions

ErdanticException

Bases: Exception

Base class for all exceptions from erdantic library.

Source code in erdantic/exceptions.py
11
12
class ErdanticException(Exception):
    """Base class for all exceptions from erdantic library."""

InvalidFieldError

Bases: ValueError, ErdanticException

Raised when an invalid field object is passed to a field adapter.

Source code in erdantic/exceptions.py
23
24
class InvalidFieldError(ValueError, ErdanticException):
    """Raised when an invalid field object is passed to a field adapter."""

InvalidModelAdapterError

Bases: ValueError, ErdanticException

Raised when a model adapter is expected but input is not subclassing Model.

Source code in erdantic/exceptions.py
19
20
class InvalidModelAdapterError(ValueError, ErdanticException):
    """Raised when a model adapter is expected but input is not subclassing Model."""

InvalidModelError

Bases: ValueError, ErdanticException

Raised when an invalid model object is passed to a model adapter.

Source code in erdantic/exceptions.py
15
16
class InvalidModelError(ValueError, ErdanticException):
    """Raised when an invalid model object is passed to a model adapter."""

ModelAdapterNotFoundError

Bases: KeyError, ErdanticException

Raised when specified key does not match a registered model adapter.

Source code in erdantic/exceptions.py
27
28
class ModelAdapterNotFoundError(KeyError, ErdanticException):
    """Raised when specified key does not match a registered model adapter."""

ModelOrModuleNotFoundError

Bases: ImportError, ErdanticException

Raised when specified fully qualified name of model class or module cannot be found.

Source code in erdantic/exceptions.py
31
32
class ModelOrModuleNotFoundError(ImportError, ErdanticException):
    """Raised when specified fully qualified name of model class or module cannot be found."""

StringForwardRefError

Bases: ErdanticException

Raised when a field's type declaration is stored as a string literal and not transformed into a typing.ForwardRef object.

Source code in erdantic/exceptions.py
39
40
41
42
43
44
45
46
47
48
49
50
class StringForwardRefError(ErdanticException):
    """Raised when a field's type declaration is stored as a string literal and not transformed
    into a typing.ForwardRef object."""

    def __init__(self, model: "Model", field: "Field", forward_ref: ForwardRef) -> None:
        message = (
            f"Forward reference '{forward_ref}' for field '{field.name}' on model '{model.name}' "
            "is a string literal and not a typing.ForwardRef object. erdantic is unable to handle "
            "forward references that aren't transformed into typing.ForwardRef. Declare "
            f"explicitly with 'typing.ForwardRef(\"{forward_ref}\", is_argument=False)'."
        )
        super().__init__(message)

UnevaluatedForwardRefError

Bases: ErdanticException

Raised when a field's type declaration has an unevaluated forward reference.

Source code in erdantic/exceptions.py
62
63
64
65
66
67
68
69
70
71
72
class UnevaluatedForwardRefError(ErdanticException):
    """Raised when a field's type declaration has an unevaluated forward reference."""

    def __init__(self, model: "Model", field: "Field", forward_ref: ForwardRef) -> None:
        message = (
            f"Unevaluated forward reference '{forward_ref.__forward_arg__}' "
            f"for field {field.name} on model {model.name}."
        )
        if model.forward_ref_help:
            message += " " + model.forward_ref_help
        super().__init__(message)

UnknownFieldError

Bases: ValueError, ErdanticException

Raised when specified field does not match a field on specified model.

Source code in erdantic/exceptions.py
84
85
class UnknownFieldError(ValueError, ErdanticException):
    """Raised when specified field does not match a field on specified model."""

UnknownModelTypeError

Bases: ValueError, ErdanticException

Raised when a given model does not match known supported class types.

Source code in erdantic/exceptions.py
88
89
90
91
92
93
94
95
96
97
class UnknownModelTypeError(ValueError, ErdanticException):
    """Raised when a given model does not match known supported class types."""

    def __init__(self, model: type, message: Optional[str] = None):
        if message is None:
            display = getattr(model, "__mro__", str(model))
            message = f"Given model does not match any supported types. Model MRO: {display}"
        self.model = model
        self.message = message
        super().__init__(message)