diff --git a/multinut/env.py b/multinut/env.py index 09fd878..46dc3d7 100644 --- a/multinut/env.py +++ b/multinut/env.py @@ -6,6 +6,10 @@ import json NO_DEFAULT = object() # Used to indicate no default value was provided +class EnviromentKeyMissing(Exception): + def __init__(self, key: str): + super().__init__(f"Environment variable '{key}' not found.") + class Modes(Enum): """ Enum for different environment modes. @@ -107,8 +111,8 @@ class Environment: If a cast function is provided, it applies the cast to the value before returning. """ - if default is NO_DEFAULT: - return cast(self.__values.get(key)) + if default is NO_DEFAULT and key not in self.__values: + raise EnviromentKeyMissing(key) return cast(self.__values.get(key, default))