Coverage for /home/admin/Documents/AI/applications/lexigram-dev/lexigram/experimental/ai/lexigram-ai-session/src/lexigram/ai/session/exceptions.py: 64%
36 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 07:19 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 07:19 +0800
1"""Errors for the lexigram-ai-session package."""
3from __future__ import annotations
5from lexigram.contracts.ai.session import SessionError as _ContractsSessionError
8class SessionError(_ContractsSessionError):
9 """Base error for all session operations.
11 All session-specific exceptions inherit from this class.
12 """
14 _code: str = "LEX_ERR_SES_006"
17class SessionNotFoundError(SessionError):
18 """Raised when a session cannot be found by its ID.
20 Args:
21 session_id: The ID of the session that was not found.
22 """
24 _code: str = "LEX_ERR_SES_007"
26 def __init__(self, session_id: str) -> None:
27 self.session_id = session_id
28 super().__init__(f"Session not found: {session_id!r}")
31class SessionClosedError(SessionError):
32 """Raised when an operation is attempted on a closed session.
34 Args:
35 session_id: The ID of the closed session.
36 """
38 _code: str = "LEX_ERR_SES_008"
40 def __init__(self, session_id: str) -> None:
41 self.session_id = session_id
42 super().__init__(f"Session is closed and cannot be modified: {session_id!r}")
45class SessionExpiredError(SessionError):
46 """Raised when an operation is attempted on an expired session.
48 Args:
49 session_id: The ID of the expired session.
50 """
52 _code: str = "LEX_ERR_SES_009"
54 def __init__(self, session_id: str) -> None:
55 self.session_id = session_id
56 super().__init__(f"Session has expired: {session_id!r}")
59class CheckpointNotFoundError(SessionError):
60 """Raised when a checkpoint cannot be found by its ID.
62 Args:
63 checkpoint_id: The ID of the checkpoint that was not found.
64 """
66 _code: str = "LEX_ERR_SES_010"
68 def __init__(self, checkpoint_id: str) -> None:
69 self.checkpoint_id = checkpoint_id
70 super().__init__(f"Checkpoint not found: {checkpoint_id!r}")
73class SessionTransitionError(SessionError):
74 """Raised when an invalid state transition is attempted.
76 Args:
77 session_id: The session ID.
78 from_status: Current status.
79 to_status: Attempted target status.
80 """
82 _code: str = "LEX_ERR_SES_011"
84 def __init__(self, session_id: str, from_status: str, to_status: str) -> None:
85 self.session_id = session_id
86 self.from_status = from_status
87 self.to_status = to_status
88 super().__init__(
89 f"Invalid transition for session {session_id!r}: "
90 f"{from_status!r} → {to_status!r}"
91 )
94class SessionCapacityError(SessionError):
95 """Raised when a session limit is exceeded.
97 Args:
98 detail: Human-readable description of the exceeded limit.
99 """
101 _code: str = "LEX_ERR_SES_012"
103 def __init__(self, detail: str) -> None:
104 super().__init__(f"Session capacity exceeded: {detail}")
107__all__ = [
108 "CheckpointNotFoundError",
109 "SessionCapacityError",
110 "SessionClosedError",
111 "SessionError",
112 "SessionExpiredError",
113 "SessionNotFoundError",
114 "SessionTransitionError",
115]