File size: 1,163 Bytes
87b48de | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | """Machine-readable error taxonomy (section 14)."""
from __future__ import annotations
from enum import Enum
from typing import Any
class ErrorCode(str, Enum):
INVALID_INPUT = "INVALID_INPUT"
UNSUPPORTED_METHOD = "UNSUPPORTED_METHOD"
RESOURCE_LIMIT = "RESOURCE_LIMIT"
TIMEOUT = "TIMEOUT"
SOLVER_FAILURE = "SOLVER_FAILURE"
NON_CONVERGENCE = "NON_CONVERGENCE"
NUMERICAL_WARNING = "NUMERICAL_WARNING"
DATA_SOURCE_UNAVAILABLE = "DATA_SOURCE_UNAVAILABLE"
CHECKSUM_MISMATCH = "CHECKSUM_MISMATCH"
CANCELLED = "CANCELLED"
UNKNOWN = "UNKNOWN"
class MatterOSError(Exception):
"""Base error carrying a taxonomy code and structured details."""
def __init__(self, code: ErrorCode, message: str, **details: Any):
super().__init__(f"{code.value}: {message}")
self.code = code
self.message = message
self.details = details
def to_dict(self) -> dict[str, Any]:
return {"error": self.code.value, "message": self.message, "details": self.details}
def invalid(message: str, **details: Any) -> MatterOSError:
return MatterOSError(ErrorCode.INVALID_INPUT, message, **details)
|