Skip to main content

recall_echo/
error.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5//! Top-level error type for recall-echo.
6//!
7//! Unifies error handling across the crate. The graph subsystem has its own
8//! `GraphError` which is wrapped here for seamless propagation.
9
10use crate::graph::error::GraphError;
11
12/// All errors that recall-echo operations can produce.
13#[derive(thiserror::Error, Debug)]
14pub enum RecallError {
15    /// I/O errors (file reads, writes, directory operations).
16    #[error("io: {0}")]
17    Io(#[from] std::io::Error),
18
19    /// JSON serialization/deserialization errors.
20    #[error("json: {0}")]
21    Json(#[from] serde_json::Error),
22
23    /// TOML serialization errors.
24    #[error("toml: {0}")]
25    TomlSerialize(#[from] toml::ser::Error),
26
27    /// TOML deserialization errors.
28    #[error("toml: {0}")]
29    TomlDeserialize(#[from] toml::de::Error),
30
31    /// Configuration errors (missing fields, invalid values).
32    #[error("config: {0}")]
33    Config(String),
34
35    /// Memory system not initialized or missing required files/directories.
36    #[error("{0}")]
37    NotInitialized(String),
38
39    /// Graph subsystem errors (wraps GraphError).
40    #[error("graph: {0}")]
41    Graph(#[from] GraphError),
42
43    /// The graph daemon could not be reached or started. Carries an actionable
44    /// message — there is no silent fallback to a direct store open.
45    #[error("graph daemon: {0}")]
46    Daemon(String),
47
48    /// A failure reported by the graph daemon, with its stable error code.
49    #[error("{message}")]
50    Remote { code: String, message: String },
51
52    /// General errors that don't fit other categories.
53    #[error("{0}")]
54    Other(String),
55}
56
57impl From<String> for RecallError {
58    fn from(s: String) -> Self {
59        RecallError::Other(s)
60    }
61}
62
63impl From<&str> for RecallError {
64    fn from(s: &str) -> Self {
65        RecallError::Other(s.to_string())
66    }
67}
68
69/// Convenience alias used across non-graph modules.
70pub type Result<T> = std::result::Result<T, RecallError>;