Coverage for src/local_deep_research/settings/exceptions.py: 93%
24 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-03 23:15 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-03 23:15 +0000
1"""Custom exception classes for the settings module."""
3from collections.abc import Sequence
4from pathlib import Path
5from typing import Any
8class EnvSettingError(ValueError):
9 """Base class for environment setting errors."""
11 def __init__(self, env_var: str, message: str):
12 self.env_var = env_var
13 super().__init__(f"{env_var}: {message}")
16class MissingEnvironmentVariableError(EnvSettingError):
17 """Raised when a required environment variable is not set."""
19 def __init__(self, env_var: str):
20 super().__init__(env_var, "Required environment variable is not set")
23class EnvironmentValueRangeError(EnvSettingError):
24 """Raised when an environment variable value is out of the allowed range."""
26 def __init__(
27 self, env_var: str, value: Any, min_val: Any = None, max_val: Any = None
28 ):
29 if min_val is not None and value < min_val:
30 msg = f"value {value} is below minimum {min_val}"
31 elif max_val is not None and value > max_val: 31 ↛ 34line 31 didn't jump to line 34 because the condition on line 31 was always true
32 msg = f"value {value} is above maximum {max_val}"
33 else:
34 msg = f"value {value} is out of range"
35 super().__init__(env_var, msg)
38class EnvironmentPathNotFoundError(EnvSettingError):
39 """Raised when a path specified in an environment variable does not exist."""
41 def __init__(self, env_var: str, path: Path | str):
42 super().__init__(env_var, f"Path {path} does not exist")
45class InvalidEnvironmentValueError(EnvSettingError):
46 """Raised when an environment variable value is not among the allowed values."""
48 def __init__(self, env_var: str, value: str, allowed_values: Sequence):
49 super().__init__(
50 env_var, f"value '{value}' not in allowed values: {allowed_values}"
51 )