Coverage for src / lexigram / contracts / infra / cache / exceptions.py: 5%
21 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-19 05:41 +0800
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-19 05:41 +0800
1"""Domain errors for cache subsystem."""
3from __future__ import annotations
5from typing import Any
7from lexigram.contracts.exceptions.domain import DomainError
10class CacheError(DomainError):
11 """Base exception for all cache-domain errors.
13 This is an expected, recoverable error that cache clients should
14 handle gracefully (e.g., miss and regenerate, fallback to origin).
15 """
17 _code = "LEX_ERR_CACHE_001"
19 def __init__(self, message: str = "Cache error", **kwargs: Any) -> None:
20 super().__init__(message, **kwargs)
23class CacheKeyNotFoundError(CacheError):
24 """Raised when cache key is not found."""
26 _code = "LEX_ERR_CACHE_002"
28 def __init__(self, key: str, **kwargs: Any) -> None:
29 self.key = key
30 message = f"Cache key not found: {key}"
31 super().__init__(message, **kwargs)
34class CacheWriteError(CacheError):
35 """Raised when cache write fails."""
37 _code = "LEX_ERR_CACHE_003"
39 def __init__(self, key: str, reason: str, **kwargs: Any) -> None:
40 self.key = key
41 self.reason = reason
42 message = f"Cache write failed for key {key}: {reason}"
43 super().__init__(message, **kwargs)
46__all__ = ["CacheError", "CacheKeyNotFoundError", "CacheWriteError"]