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

1"""Domain errors for cache subsystem.""" 

2 

3from __future__ import annotations 

4 

5from typing import Any 

6 

7from lexigram.contracts.exceptions.domain import DomainError 

8 

9 

10class CacheError(DomainError): 

11 """Base exception for all cache-domain errors. 

12 

13 This is an expected, recoverable error that cache clients should 

14 handle gracefully (e.g., miss and regenerate, fallback to origin). 

15 """ 

16 

17 _code = "LEX_ERR_CACHE_001" 

18 

19 def __init__(self, message: str = "Cache error", **kwargs: Any) -> None: 

20 super().__init__(message, **kwargs) 

21 

22 

23class CacheKeyNotFoundError(CacheError): 

24 """Raised when cache key is not found.""" 

25 

26 _code = "LEX_ERR_CACHE_002" 

27 

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) 

32 

33 

34class CacheWriteError(CacheError): 

35 """Raised when cache write fails.""" 

36 

37 _code = "LEX_ERR_CACHE_003" 

38 

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) 

44 

45 

46__all__ = ["CacheError", "CacheKeyNotFoundError", "CacheWriteError"]