Coverage for src/lexigram/admin/exceptions.py: 10%

29 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-24 23:31 +0800

1"""Admin exceptions - consolidated to base framework exceptions.""" 

2 

3from __future__ import annotations 

4 

5from enum import StrEnum 

6 

7from lexigram.contracts.exceptions import DomainError, LexigramError 

8from lexigram.contracts.exceptions import ValidationError as BaseValidationError 

9 

10 

11class ErrorCode(StrEnum): 

12 """Machine-readable error codes for admin operations.""" 

13 

14 AUTH_INVALID_TOKEN = "AUTH_INVALID_TOKEN" # noqa: S105 # error code name, not a credential 

15 AUTH_SESSION_EXPIRED = "AUTH_SESSION_EXPIRED" 

16 AUTH_PERMISSION_DENIED = "AUTH_PERMISSION_DENIED" 

17 AUTH_NOT_AUTHENTICATED = "AUTH_NOT_AUTHENTICATED" 

18 RESOURCE_NOT_FOUND = "RESOURCE_NOT_FOUND" 

19 RESOURCE_CONFLICT = "RESOURCE_CONFLICT" 

20 VALIDATION_FAILED = "VALIDATION_FAILED" 

21 

22 

23class AdminError(LexigramError): 

24 """Base exception for all admin errors.""" 

25 

26 _code: str = "LEX_ERR_ADMIN_002" 

27 

28 

29class NotFoundError(DomainError): 

30 """Raised when a resource is not found.""" 

31 

32 _code: str = "LEX_ERR_ADMIN_003" 

33 

34 

35class PermissionDeniedError(DomainError): 

36 """Raised when permission is denied.""" 

37 

38 _code: str = "LEX_ERR_ADMIN_004" 

39 

40 

41class ConflictError(DomainError): 

42 """Raised when a resource conflict occurs.""" 

43 

44 _code: str = "LEX_ERR_ADMIN_005" 

45 

46 

47class AdminValidationError(BaseValidationError): 

48 """Raised when validation fails.""" 

49 

50 _code: str = "LEX_ERR_ADMIN_006" 

51 

52 

53class DataError(DomainError): 

54 """Raised when a data source or database error occurs in admin.""" 

55 

56 _code: str = "LEX_ERR_ADMIN_007" 

57 

58 

59class AdminDataError(AdminError): 

60 """Raised when a storage/database operation fails. 

61 

62 Translates low-level database exceptions to a domain-level error 

63 to prevent infrastructure details from bubbling up to the UI. 

64 """ 

65 

66 _code: str = "LEX_ERR_ADMIN_008" 

67 

68 

69class NotificationError(DomainError): 

70 """Raised when a notification fails to send.""" 

71 

72 _code: str = "LEX_ERR_ADMIN_009" 

73 

74 

75__all__ = [ 

76 "AdminDataError", 

77 "AdminError", 

78 "AdminValidationError", 

79 "ConflictError", 

80 "DataError", 

81 "ErrorCode", 

82 "NotFoundError", 

83 "NotificationError", 

84 "PermissionDeniedError", 

85]