Skip to main content

turul_mcp_task_storage/
error.rs

1//! Unified error types for task storage operations.
2
3use turul_mcp_protocol::TaskStatus;
4
5/// Unified error type for task storage operations.
6///
7/// Mirrors the pattern used in `turul-mcp-session-storage` for consistency.
8#[derive(Debug, thiserror::Error)]
9pub enum TaskStorageError {
10    #[error("Task not found: {0}")]
11    TaskNotFound(String),
12
13    #[error("Invalid state transition: {current:?} -> {requested:?}")]
14    InvalidTransition {
15        current: TaskStatus,
16        requested: TaskStatus,
17    },
18
19    #[error("Task is in terminal state: {0:?}")]
20    TerminalState(TaskStatus),
21
22    #[error("Task has expired: {0}")]
23    TaskExpired(String),
24
25    #[error("Maximum tasks limit reached: {0}")]
26    MaxTasksReached(usize),
27
28    #[error("Concurrent modification: {0}")]
29    ConcurrentModification(String),
30
31    #[error("Database error: {0}")]
32    DatabaseError(String),
33
34    #[error("Serialization error: {0}")]
35    SerializationError(String),
36
37    #[error("Generic storage error: {0}")]
38    Generic(String),
39}
40
41impl From<serde_json::Error> for TaskStorageError {
42    fn from(err: serde_json::Error) -> Self {
43        TaskStorageError::SerializationError(err.to_string())
44    }
45}
46
47#[cfg(any(feature = "sqlite", feature = "postgres"))]
48impl From<sqlx::Error> for TaskStorageError {
49    fn from(err: sqlx::Error) -> Self {
50        TaskStorageError::DatabaseError(err.to_string())
51    }
52}