attuned_store/
error.rs

1//! Storage error types.
2
3use thiserror::Error;
4
5/// Errors that can occur during storage operations.
6#[derive(Debug, Error)]
7#[non_exhaustive]
8pub enum StoreError {
9    /// User was not found in the store.
10    #[error("user not found: {user_id}")]
11    UserNotFound {
12        /// The user ID that was not found.
13        user_id: String,
14    },
15
16    /// Internal storage error.
17    #[error("storage error: {message}")]
18    Internal {
19        /// Error message.
20        message: String,
21        /// Underlying error source.
22        #[source]
23        source: Option<Box<dyn std::error::Error + Send + Sync>>,
24    },
25
26    /// Connection error (for remote stores).
27    #[error("connection error: {message}")]
28    Connection {
29        /// Error message.
30        message: String,
31        /// Underlying error source.
32        #[source]
33        source: Option<Box<dyn std::error::Error + Send + Sync>>,
34    },
35
36    /// Validation error.
37    #[error("validation error: {0}")]
38    Validation(#[from] attuned_core::ValidationError),
39}
40
41impl StoreError {
42    /// Create a new internal error.
43    pub fn internal(message: impl Into<String>) -> Self {
44        Self::Internal {
45            message: message.into(),
46            source: None,
47        }
48    }
49
50    /// Create a new internal error with a source.
51    pub fn internal_with_source(
52        message: impl Into<String>,
53        source: impl std::error::Error + Send + Sync + 'static,
54    ) -> Self {
55        Self::Internal {
56            message: message.into(),
57            source: Some(Box::new(source)),
58        }
59    }
60
61    /// Create a new connection error.
62    pub fn connection(message: impl Into<String>) -> Self {
63        Self::Connection {
64            message: message.into(),
65            source: None,
66        }
67    }
68}