1use thiserror::Error;
4
5#[derive(Debug, Error)]
7#[non_exhaustive]
8pub enum StoreError {
9 #[error("user not found: {user_id}")]
11 UserNotFound {
12 user_id: String,
14 },
15
16 #[error("storage error: {message}")]
18 Internal {
19 message: String,
21 #[source]
23 source: Option<Box<dyn std::error::Error + Send + Sync>>,
24 },
25
26 #[error("connection error: {message}")]
28 Connection {
29 message: String,
31 #[source]
33 source: Option<Box<dyn std::error::Error + Send + Sync>>,
34 },
35
36 #[error("validation error: {0}")]
38 Validation(#[from] attuned_core::ValidationError),
39}
40
41impl StoreError {
42 pub fn internal(message: impl Into<String>) -> Self {
44 Self::Internal {
45 message: message.into(),
46 source: None,
47 }
48 }
49
50 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 pub fn connection(message: impl Into<String>) -> Self {
63 Self::Connection {
64 message: message.into(),
65 source: None,
66 }
67 }
68}