Skip to main content

alice_core/memory/
error.rs

1//! Error types for the memory subsystem.
2
3/// Validation failures for memory inputs.
4#[derive(Debug, thiserror::Error, Clone, PartialEq)]
5pub enum MemoryValidationError {
6    /// Hybrid weights are outside expected range.
7    #[error("invalid hybrid weights: bm25={bm25}, vector={vector}")]
8    InvalidHybridWeights {
9        /// Provided BM25 weight.
10        bm25: f32,
11        /// Provided vector weight.
12        vector: f32,
13    },
14    /// Recall limit must be positive.
15    #[error("recall limit must be greater than zero")]
16    InvalidRecallLimit,
17}
18
19/// Storage adapter failures.
20#[derive(Debug, thiserror::Error)]
21pub enum MemoryStoreError {
22    /// Database operation failed.
23    #[error("database error: {0}")]
24    Database(String),
25    /// Serialization or deserialization failed.
26    #[error("serialization error: {0}")]
27    Serialization(String),
28    /// Input validation failed.
29    #[error(transparent)]
30    Validation(#[from] MemoryValidationError),
31}
32
33/// Memory service failures.
34#[derive(Debug, thiserror::Error)]
35pub enum MemoryServiceError {
36    /// Service-level validation issue.
37    #[error(transparent)]
38    Validation(#[from] MemoryValidationError),
39    /// Store layer failure.
40    #[error(transparent)]
41    Store(#[from] MemoryStoreError),
42}
43
44impl From<serde_json::Error> for MemoryStoreError {
45    fn from(value: serde_json::Error) -> Self {
46        Self::Serialization(value.to_string())
47    }
48}