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    /// The graph daemon could not be reached or started. Carries an actionable
40    /// message — there is no silent fallback to a direct store open.
41    #[error("graph daemon: {0}")]
42    Daemon(String),
43
44    /// A failure reported by the graph daemon, with its stable error code.
45    #[error("{message}")]
46    Remote { code: String, message: String },
47
48    /// General errors that don't fit other categories.
49    #[error("{0}")]
50    Other(String),
51}
52
53impl From<String> for RecallError {
54    fn from(s: String) -> Self {
55        RecallError::Other(s)
56    }
57}
58
59impl From<&str> for RecallError {
60    fn from(s: &str) -> Self {
61        RecallError::Other(s.to_string())
62    }
63}
64
65/// Convenience alias used across non-graph modules.
66pub type Result<T> = std::result::Result<T, RecallError>;