agent_memory/
error.rs

1//! Error types for the memory subsystem.
2
3use serde_json::Error as SerdeError;
4use thiserror::Error;
5
6/// Errors emitted by memory components.
7#[derive(Debug, Error)]
8pub enum MemoryError {
9    /// The provided configuration was invalid.
10    #[error("invalid memory configuration: {0}")]
11    InvalidConfig(&'static str),
12    /// Underlying I/O failure while reading or writing journal files.
13    #[error("i/o error: {source}")]
14    Io {
15        /// Source [`std::io::Error`].
16        #[from]
17        source: std::io::Error,
18    },
19    /// Serialization or deserialization error.
20    #[error("serialization error: {source}")]
21    Serialization {
22        /// Source [`serde_json::Error`].
23        #[from]
24        source: SerdeError,
25    },
26    /// Operation that requires a configured journal was invoked without one.
27    #[error("memory journal not configured")]
28    MissingJournal,
29    /// Operation that requires a configured vector store was invoked without one.
30    #[error("vector store client not configured")]
31    MissingVectorStore,
32    /// Vector store backend reported an application error.
33    #[error("vector store error: {reason}")]
34    VectorStore {
35        /// Human-readable reason describing the failure.
36        reason: String,
37    },
38    /// Memory record metadata failed validation.
39    #[error("invalid memory record: {0}")]
40    InvalidRecord(&'static str),
41}
42
43impl MemoryError {
44    /// Helper to construct vector store errors from string-like values.
45    #[must_use]
46    pub fn vector_store(reason: impl Into<String>) -> Self {
47        Self::VectorStore {
48            reason: reason.into(),
49        }
50    }
51}
52
53/// Result type alias for memory operations.
54pub type MemoryResult<T> = Result<T, MemoryError>;