Coverage for src / lexigram / contracts / exceptions / resilience.py: 0%
36 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-15 18:57 +0800
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-15 18:57 +0800
1"""Resilience pattern exception classes."""
3from __future__ import annotations
5from typing import Any
7from lexigram.contracts.exceptions.base import LexigramError
10class ResilienceError(LexigramError):
11 """Base resilience error."""
13 _code = "LEX_ERR_RES_001"
15 def __init__(self, message: str = "Resilience error", **kwargs: Any) -> None:
16 super().__init__(message, **kwargs)
19class RetryError(ResilienceError):
20 """Retry operation error."""
22 _code = "LEX_ERR_RES_002"
24 def __init__(self, message: str = "Retry error", **kwargs: Any) -> None:
25 super().__init__(message, **kwargs)
28class CircuitBreakerError(ResilienceError):
29 """Circuit breaker error."""
31 _code = "LEX_ERR_RES_003"
33 def __init__(self, message: str = "Circuit breaker error", **kwargs: Any) -> None:
34 super().__init__(message, **kwargs)
37class BulkheadError(ResilienceError):
38 """Bulkhead/rejection error."""
40 _code = "LEX_ERR_RES_004"
42 def __init__(self, message: str = "Bulkhead rejected", **kwargs: Any) -> None:
43 super().__init__(message, **kwargs)
46class FallbackError(ResilienceError):
47 """Fallback execution error."""
49 _code = "LEX_ERR_RES_005"
51 def __init__(self, message: str = "Fallback error", **kwargs: Any) -> None:
52 super().__init__(message, **kwargs)
55class RetryExhaustedError(RetryError):
56 """All retry attempts have been exhausted."""
58 _code = "LEX_ERR_RES_006"
60 def __init__(
61 self,
62 message: str = "All retry attempts exhausted",
63 attempts: int = 0,
64 **kwargs: Any,
65 ) -> None:
66 details = kwargs.get("details", {})
67 details["attempts"] = attempts
68 kwargs["details"] = details
69 super().__init__(message, **kwargs)
70 self.attempts = attempts
73class CircuitOpenError(CircuitBreakerError):
74 """Circuit breaker is open and rejecting requests."""
76 _code = "LEX_ERR_RES_007"
78 def __init__(
79 self,
80 message: str = "Circuit breaker is open",
81 **kwargs: Any,
82 ) -> None:
83 super().__init__(message, **kwargs)
86__all__ = [
87 "BulkheadError",
88 "CircuitBreakerError",
89 "CircuitOpenError",
90 "FallbackError",
91 "ResilienceError",
92 "RetryError",
93 "RetryExhaustedError",
94]