Skip to main content

zeph_memory/
error.rs

1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4/// Top-level error type for all `zeph-memory` operations.
5///
6/// Wraps database, vector-store, LLM, and serialization errors into a single type
7/// consumed by callers in `zeph-core`.
8///
9/// # Examples
10///
11/// ```rust
12/// use zeph_memory::MemoryError;
13///
14/// fn demo(e: MemoryError) -> String {
15///     e.to_string()
16/// }
17/// ```
18#[derive(Debug, thiserror::Error)]
19#[non_exhaustive]
20pub enum MemoryError {
21    #[error("sqlx error: {0}")]
22    Sqlx(#[from] zeph_db::SqlxError),
23
24    #[error("db error: {0}")]
25    Db(#[from] zeph_db::DbError),
26
27    #[error("Qdrant error: {0}")]
28    Qdrant(#[from] Box<qdrant_client::QdrantError>),
29
30    #[error("vector store error: {0}")]
31    VectorStore(#[from] crate::vector_store::VectorStoreError),
32
33    #[error("LLM error: {0}")]
34    Llm(#[from] zeph_llm::LlmError),
35
36    #[error("JSON error: {0}")]
37    Json(#[from] serde_json::Error),
38
39    #[error("integer conversion: {0}")]
40    IntConversion(#[from] std::num::TryFromIntError),
41
42    #[error("snapshot error: {0}")]
43    Snapshot(String),
44
45    #[error("I/O error: {0}")]
46    Io(#[from] std::io::Error),
47
48    #[error("graph store error: {0}")]
49    GraphStore(String),
50
51    #[error("invalid input: {0}")]
52    InvalidInput(String),
53
54    /// A mutex or `RwLock` was poisoned by a panicking thread.
55    ///
56    /// This indicates a programming error (a thread panicked while holding the lock).
57    /// The inner string describes which lock was poisoned.
58    #[error("lock poisoned: {0}")]
59    LockPoisoned(String),
60
61    /// Catch-all for errors that do not yet have a specific typed variant.
62    ///
63    /// # Deprecation
64    ///
65    /// Prefer adding a typed variant over using `Other`. This variant exists for
66    /// backward compatibility and will be removed once all callsites are migrated.
67    #[error("{0}")]
68    Other(String),
69
70    #[error("operation timed out: {0}")]
71    Timeout(String),
72
73    /// Returned when inserting a supersede pointer would form a cycle in the chain.
74    #[error("supersede cycle detected at edge id={0}")]
75    SupersedeCycle(i64),
76
77    /// Returned when the supersede chain depth would exceed [`crate::graph::conflict::SUPERSEDE_DEPTH_CAP`].
78    #[error("supersede chain depth cap exceeded at edge id={0}")]
79    SupersedeDepthExceeded(i64),
80
81    /// A promotion-scan or promote error (Feature A, #3305).
82    ///
83    /// Wraps errors from clustering, skill generation, evaluator calls, or disk writes.
84    #[error("promotion scan failed: {0}")]
85    Promotion(String),
86}
87
88#[cfg(test)]
89mod tests {
90    use super::MemoryError;
91
92    #[test]
93    fn sqlx_variant_display() {
94        let inner = zeph_db::SqlxError::RowNotFound;
95        let err = MemoryError::Sqlx(inner);
96        assert!(
97            err.to_string().starts_with("sqlx error:"),
98            "unexpected display: {err}"
99        );
100    }
101
102    #[test]
103    fn db_variant_display() {
104        let inner = zeph_db::DbError::Io(std::io::Error::new(std::io::ErrorKind::NotFound, "test"));
105        let err = MemoryError::Db(inner);
106        assert!(
107            err.to_string().starts_with("db error:"),
108            "unexpected display: {err}"
109        );
110    }
111}