Skip to main content

forge_reasoning/
errors.rs

1//! Error types for reasoning tools
2
3use thiserror::Error;
4
5/// Main error type for reasoning tools
6#[derive(Error, Debug)]
7pub enum ReasoningError {
8    /// Storage-related errors
9    #[error("Storage error: {0}")]
10    Storage(#[from] StorageError),
11
12    /// Checkpoint-specific errors
13    #[error("Checkpoint error: {0}")]
14    Checkpoint(#[from] CheckpointError),
15
16    /// Serialization/deserialization errors
17    #[error("Serialization error: {0}")]
18    Serialization(#[from] serde_json::Error),
19
20    /// Generic IO errors
21    #[error("IO error: {0}")]
22    Io(#[from] std::io::Error),
23
24    /// Invalid state or operation
25    #[error("Invalid state: {0}")]
26    InvalidState(String),
27
28    /// Not found
29    #[error("Not found: {0}")]
30    NotFound(String),
31
32    /// Validation failed (checksum mismatch, etc.)
33    #[error("Validation failed: {0}")]
34    ValidationFailed(String),
35}
36
37/// Storage-specific errors
38#[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/// Checkpoint-specific errors
60#[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
75/// Result type alias for reasoning operations
76pub type Result<T> = std::result::Result<T, ReasoningError>;
77
78/// Convert SQLiteGraph errors
79impl From<sqlitegraph::SqliteGraphError> for ReasoningError {
80    fn from(err: sqlitegraph::SqliteGraphError) -> Self {
81        ReasoningError::Storage(StorageError::ConnectionFailed(err.to_string()))
82    }
83}