env_proxy.exceptions¶
exceptions ¶
Exceptions raised by env-proxy.
:class:EnvProxyError is the catch-all base for every typed exception
raised by this library. The three value-shaped subclasses
(:class:EnvKeyMissingError, :class:EnvValueError,
:class:EnvValidationError) also inherit from :class:ValueError so
except ValueError: keeps working. :class:EnvConfigError — raised
for declaration/resolution mistakes — additionally inherits from
:class:RuntimeError because its call sites previously raised raw
RuntimeError and the dual inheritance preserves that back-compat.
Three documented deviations exist on purpose and are not
:class:EnvProxyError instances:
- :class:
json.JSONDecodeErrorfrom :meth:EnvProxy.get_json— propagated as-is by design; it is itself a :class:ValueErrorsubclass. - :class:
RuntimeErrorfrom :attr:EnvField.field_name/ :attr:EnvField.owner— only reachable if a free-floatingField()instance is used outside a class body; treated as a bug indicator. - :class:
TypeErrorfrom assignment to a frozen instance or a non-allow_setfield — matches the standard library's@dataclass(frozen=True)idiom.
EnvProxyError ¶
Bases: Exception
Base class for every exception raised by env-proxy.
EnvKeyMissingError ¶
Bases: EnvProxyError, ValueError
Raised when a required env var is absent and no default was given.
The env var name is available on :attr:key.
Source code in env_proxy/exceptions.py
EnvValueError ¶
Bases: EnvProxyError, ValueError
Raised when an env value cannot be converted to the target type.
Inspect :attr:key, :attr:value, and :attr:target for the
failing env var name, its raw string value, and the type label.
The underlying exception (e.g. from a custom convert_using
callable) is preserved on __cause__.
Source code in env_proxy/exceptions.py
EnvValidationError ¶
Bases: EnvProxyError, ValueError
Raised by :meth:EnvConfig.validate with every field failure aggregated.
:attr:errors is a mapping from Python field name to the underlying
:class:EnvProxyError for that field (typically an
:class:EnvKeyMissingError or :class:EnvValueError).
Source code in env_proxy/exceptions.py
EnvConfigError ¶
Bases: EnvProxyError, RuntimeError, ValueError
Raised when an :class:EnvConfig is declared or resolved incorrectly.
Covers: unsupported type_hint= strings, strict-mode failures to
determine a value getter from an annotation (missing or too-complex
annotation), reserved field names, unknown override keys passed to
:class:EnvConfig, and type_hint='json' fields whose default is
not JSON-encodable.
Inherits from both :class:RuntimeError and :class:ValueError so
that legacy except RuntimeError / except ValueError handlers
keep working after the migration from raw built-in exceptions. New
code should prefer except EnvProxyError (or this class directly)
for clarity.