"""Custom exceptions for the Metric Engine."""
from collections.abc import Sequence
from typing import Optional
[docs]
class MetricEngineError(Exception):
"""Base exception for all Metric Engine errors."""
pass
[docs]
class CircularDependencyError(MetricEngineError):
"""Raised when a circular dependency is detected in calculations."""
def __init__(self, cycle: Sequence[str]):
self.cycle = tuple(cycle)
cycle_str = " -> ".join(self.cycle)
super().__init__(f"Circular dependency detected: {cycle_str}")
def __repr__(self) -> str:
return f"CircularDependencyError({self.cycle})"
[docs]
class CalculationError(MetricEngineError):
"""Generic calculation error."""
def __init__(self, message: str, calculation_name: Optional[str] = None):
super().__init__(message)
self.calculation_name = calculation_name
def __repr__(self) -> str:
return f"CalculationError('{self}', calculation_name='{self.calculation_name}')"