- Add standalone ConfigError(Exception) in errors.py decoupled from runtime TvError - Convert TvConfig from dataclass to frozen Pydantic v2 BaseModel with field_validator hooks using PydanticCustomError - Validate TV_IP and WOL_BROADCAST as IPv4 addresses, PORT in 1..65535, and MAX_VOLUME in 0..100 on both load_config() and direct TvConfig instantiation - Redirect Pydantic ValidationError to ConfigError in TvConfig.__init__ and raise ConfigError from require_bearer_token/require_mac - Declare pydantic explicitly in flake.nix runtimeDeps and pyproject.toml dependencies - Expand tests/test_config.py to cover ConfigError and direct TvConfig validation
33 lines
944 B
Python
33 lines
944 B
Python
"""Typed domain error taxonomy for lg-smtv-mcp."""
|
|
|
|
from enum import StrEnum
|
|
|
|
|
|
class ErrorCode(StrEnum):
|
|
"""Canonical error codes mapped to MCP tool errors."""
|
|
|
|
TV_OFFLINE_STANDBY = "TV_OFFLINE_STANDBY"
|
|
PAIRING_REQUIRED = "PAIRING_REQUIRED"
|
|
SCREENSHOT_UNAVAILABLE = "SCREENSHOT_UNAVAILABLE"
|
|
LOCK_TIMEOUT = "LOCK_TIMEOUT"
|
|
WAKE_TIMEOUT = "WAKE_TIMEOUT"
|
|
COMMAND_FAILED = "COMMAND_FAILED"
|
|
INVALID_ARGUMENT = "INVALID_ARGUMENT"
|
|
|
|
|
|
class TvError(Exception):
|
|
"""Domain error carrying a structured ErrorCode and message."""
|
|
|
|
def __init__(self, code: ErrorCode, message: str) -> None:
|
|
super().__init__(f"{code.value}: {message}")
|
|
self.code = code
|
|
self.message = message
|
|
|
|
|
|
class ConfigError(Exception):
|
|
"""Raised when runtime configuration is missing or fails validation."""
|
|
|
|
def __init__(self, message: str) -> None:
|
|
super().__init__(message)
|
|
self.message = message
|