Skip to content

erdantic.exceptions

ErdanticException

Bases: Exception

Base class for all exceptions from erdantic library.

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

FieldNotFoundError

Bases: AttributeError, ErdanticException

Raised trying to access a field name that does not match any fields returned by the field extractor function for a model.

Attributes:

Name Type Description
name str

The name of the field that was not found.

obj object

The model object that the field was being accessed on.

model_full_name FullyQualifiedName

The fully qualified name of the model.

Source code in erdantic/exceptions.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
class FieldNotFoundError(AttributeError, ErdanticException):
    """Raised trying to access a field name that does not match any fields returned by the
    field extractor function for a model.

    Attributes:
        name (str): The name of the field that was not found.
        obj (object): The model object that the field was being accessed on.
        model_full_name (FullyQualifiedName): The fully qualified name of the model.
    """

    def __init__(self, *args, name: str, obj: object, model_full_name: "FullyQualifiedName"):
        self.model_full_name = model_full_name
        msg = f"Model '{model_full_name}' has no field '{name}'."
        if sys.version_info >= (3, 10):
            super().__init__(*args, msg, name=name, obj=obj)
        else:
            self.name = name
            self.obj = obj
            super().__init__(*args, msg)

ModelOrModuleNotFoundError

Bases: ImportError, ErdanticException

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

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

PluginNotFoundError

Bases: KeyError, ErdanticException

Raised when specified plugin key does not match a registered plugin.

Attributes:

Name Type Description
key str

The plugin key that was not found.

Source code in erdantic/exceptions.py
12
13
14
15
16
17
18
19
20
21
22
class PluginNotFoundError(KeyError, ErdanticException):
    """Raised when specified plugin key does not match a registered plugin.

    Attributes:
        key (str): The plugin key that was not found.
    """

    def __init__(self, *args: object, key: str) -> None:
        self.key = key
        message = f"Specified plugin not found: '{key}'"
        super().__init__(*args, message)

UnevaluatedForwardRefError

Bases: ErdanticException

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

Attributes:

Name Type Description
model_full_name FullyQualifiedName

The fully qualified name of the model with the field with the unevaluated forward reference.

field_name str

The name of the field with the unevaluated forward reference.

forward_ref str

The string representation of the unevaluated forward reference.

Source code in erdantic/exceptions.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
class UnevaluatedForwardRefError(ErdanticException):
    """Raised when a field's type declaration has an unevaluated forward reference.

    Attributes:
        model_full_name (FullyQualifiedName): The fully qualified name of the model with the field
            with the unevaluated forward reference.
        field_name (str): The name of the field with the unevaluated forward reference.
        forward_ref (str): The string representation of the unevaluated forward reference.
    """

    def __init__(
        self,
        *args: object,
        model_full_name: "FullyQualifiedName",
        field_name: str,
        forward_ref: str,
    ) -> None:
        self.model_full_name = model_full_name
        self.field_name = field_name
        self.forward_ref = forward_ref
        message = (
            f"Unevaluated forward reference '{forward_ref}' "
            f"for field '{field_name}' on model '{model_full_name}'. "
            "Normally, erdantic plugins try to resolve forward references automatically, and this "
            "error indicates that this didn't happen. If you are using a built-in plugin, please "
            "report this as a bug. If you are using a custom or third-party plugin, then that "
            "plugin needs to add support for automatically resolving forward references. "
        )
        super().__init__(*args, message)

UnknownModelTypeError

Bases: ValueError, ErdanticException

Raised when a given model does not match known model types from loaded plugins.

Attributes:

Name Type Description
model type

The model class that was not recognized.

available_plugins List[str]

List of plugin keys that were available.

Source code in erdantic/exceptions.py
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
class UnknownModelTypeError(ValueError, ErdanticException):
    """Raised when a given model does not match known model types from loaded plugins.

    Attributes:
        model (type): The model class that was not recognized.
        available_plugins (List[str]): List of plugin keys that were available.
    """

    def __init__(self, *args, model: type, available_plugins: List[str]):
        mro = getattr(model, "__mro__", str(model))
        message = (
            "Given model does not match any supported types. "
            f"Available plugins: {available_plugins}. "
            f"Model MRO: {mro}"
        )
        self.model = model
        self.available_plugins = available_plugins
        super().__init__(*args, message)

UnresolvableForwardRefError

Bases: NameError, ErdanticException

Raised when a forward reference in a type annotation cannot be resolved automatically.

Attributes:

Name Type Description
name str

The string representation of the unresolvable forward reference.

Source code in erdantic/exceptions.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class UnresolvableForwardRefError(NameError, ErdanticException):
    """Raised when a forward reference in a type annotation cannot be resolved automatically.

    Attributes:
        name (str): The string representation of the unresolvable forward reference.
    """

    def __init__(
        self,
        *args: object,
        name: str,
        model_full_name: "FullyQualifiedName",
    ) -> None:
        self.model_full_name = model_full_name
        if sys.version_info >= (3, 10):
            # typeshed is wrong; NameError does have keyword argument 'name'
            super().__init__(*args, name=name)  # type: ignore [call-arg]
        else:
            super().__init__(*args)
            self.name = name