feat: add custom exception for missing environment variables

This commit is contained in:
Chipperfluff 2025-07-05 17:35:56 +02:00
parent 2cc01e1b2f
commit 76c1a2b67f

View File

@ -6,6 +6,10 @@ import json
NO_DEFAULT = object() # Used to indicate no default value was provided 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): class Modes(Enum):
""" """
Enum for different environment modes. 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 a cast function is provided, it applies the cast to the value before returning.
""" """
if default is NO_DEFAULT: if default is NO_DEFAULT and key not in self.__values:
return cast(self.__values.get(key)) raise EnviromentKeyMissing(key)
return cast(self.__values.get(key, default)) return cast(self.__values.get(key, default))