Skip to content

erdantic.exceptions

Classes

ErdanticException (Exception)

Base class for all exceptions from erdantic library.

InvalidFieldError (ValueError, ErdanticException)

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

InvalidModelAdapterError (ValueError, ErdanticException)

Raised when trying to register a model adapter that is not subclassing Model.

InvalidModelError (ValueError, ErdanticException)

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

NotATypeError (ValueError, ErdanticException)

StringForwardRefError (ErdanticException)

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

__init__(self, model: Model, field: Field, forward_ref: ForwardRef) -> None special
Source code in erdantic/exceptions.py
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)'."
    )
    if sys.version_info[:3] < (3, 7, 4):
        message = message.replace("typing.ForwardRef", "typing._ForwardRef")

    super().__init__(message)

UnevaluatedForwardRefError (ErdanticException)

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

__init__(self, model: Model, field: Field, forward_ref: ForwardRef) -> None special
Source code in erdantic/exceptions.py
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 (ValueError, ErdanticException)

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

UnknownModelTypeError (ValueError, ErdanticException)

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

__init__(self, model: type, message: Optional[str] = None) special
Source code in erdantic/exceptions.py
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)
Back to top