Skip to main content

recall_echo/
error.rs

1//! Top-level error type for recall-echo.
2//!
3//! Unifies error handling across the crate. The graph subsystem has its own
4//! `GraphError` which is wrapped here for seamless propagation.
5
6use crate::graph::error::GraphError;
7
8/// All errors that recall-echo operations can produce.
9#[derive(thiserror::Error, Debug)]
10pub enum RecallError {
11    /// I/O errors (file reads, writes, directory operations).
12    #[error("io: {0}")]
13    Io(#[from] std::io::Error),
14
15    /// JSON serialization/deserialization errors.
16    #[error("json: {0}")]
17    Json(#[from] serde_json::Error),
18
19    /// TOML serialization errors.
20    #[error("toml: {0}")]
21    TomlSerialize(#[from] toml::ser::Error),
22
23    /// TOML deserialization errors.
24    #[error("toml: {0}")]
25    TomlDeserialize(#[from] toml::de::Error),
26
27    /// Configuration errors (missing fields, invalid values).
28    #[error("config: {0}")]
29    Config(String),
30
31    /// Memory system not initialized or missing required files/directories.
32    #[error("{0}")]
33    NotInitialized(String),
34
35    /// Graph subsystem errors (wraps GraphError).
36    #[error("graph: {0}")]
37    Graph(#[from] GraphError),
38
39    /// General errors that don't fit other categories.
40    #[error("{0}")]
41    Other(String),
42}
43
44impl From<String> for RecallError {
45    fn from(s: String) -> Self {
46        RecallError::Other(s)
47    }
48}
49
50impl From<&str> for RecallError {
51    fn from(s: &str) -> Self {
52        RecallError::Other(s.to_string())
53    }
54}
55
56/// Convenience alias used across non-graph modules.
57pub type Result<T> = std::result::Result<T, RecallError>;