forge_reasoning/
errors.rs1use thiserror::Error;
4
5#[derive(Error, Debug)]
7pub enum ReasoningError {
8 #[error("Storage error: {0}")]
10 Storage(#[from] StorageError),
11
12 #[error("Checkpoint error: {0}")]
14 Checkpoint(#[from] CheckpointError),
15
16 #[error("Serialization error: {0}")]
18 Serialization(#[from] serde_json::Error),
19
20 #[error("IO error: {0}")]
22 Io(#[from] std::io::Error),
23
24 #[error("Invalid state: {0}")]
26 InvalidState(String),
27
28 #[error("Not found: {0}")]
30 NotFound(String),
31
32 #[error("Validation failed: {0}")]
34 ValidationFailed(String),
35}
36
37#[derive(Error, Debug)]
39pub enum StorageError {
40 #[error("Failed to connect to storage: {0}")]
41 ConnectionFailed(String),
42
43 #[error("Failed to store checkpoint: {0}")]
44 StoreFailed(String),
45
46 #[error("Failed to retrieve checkpoint: {0}")]
47 RetrieveFailed(String),
48
49 #[error("Failed to list checkpoints: {0}")]
50 ListFailed(String),
51
52 #[error("Failed to delete checkpoint: {0}")]
53 DeleteFailed(String),
54
55 #[error("Backend not available: {0}")]
56 BackendNotAvailable(String),
57}
58
59#[derive(Error, Debug)]
61pub enum CheckpointError {
62 #[error("Checkpoint not found: {0}")]
63 NotFound(String),
64
65 #[error("Checkpoint already exists: {0}")]
66 AlreadyExists(String),
67
68 #[error("Failed to capture state: {0}")]
69 CaptureFailed(String),
70
71 #[error("Failed to restore state: {0}")]
72 RestoreFailed(String),
73}
74
75pub type Result<T> = std::result::Result<T, ReasoningError>;
77
78impl From<sqlitegraph::SqliteGraphError> for ReasoningError {
80 fn from(err: sqlitegraph::SqliteGraphError) -> Self {
81 ReasoningError::Storage(StorageError::ConnectionFailed(err.to_string()))
82 }
83}