Skip to main content

aa_core/storage/
error.rs

1//! Error type shared by every storage trait.
2
3/// Failure modes common to all storage backends.
4///
5/// Backends map their native errors (a `sqlx::Error`, a `redis::RedisError`, a
6/// `tonic::Status`, …) onto these variants so callers never depend on a concrete
7/// backend's error type. The string payloads carry backend-specific detail for
8/// logging without leaking the backend's types into this crate's public API.
9#[derive(Debug, thiserror::Error)]
10#[non_exhaustive]
11pub enum StorageError {
12    /// The requested entity does not exist in the backend.
13    #[error("storage entity not found: {0}")]
14    NotFound(String),
15
16    /// The backend is unreachable or returned a transport/connection failure.
17    #[error("storage backend unavailable: {0}")]
18    Backend(String),
19
20    /// Stored bytes could not be encoded to or decoded from the domain type.
21    #[error("storage serialization error: {0}")]
22    Serialization(String),
23
24    /// The write conflicts with existing state (optimistic-concurrency or
25    /// uniqueness violation).
26    #[error("storage conflict: {0}")]
27    Conflict(String),
28}
29
30/// Convenience alias for results returned by storage trait methods.
31pub type Result<T> = core::result::Result<T, StorageError>;