use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum StoreError {
#[error("user not found: {user_id}")]
UserNotFound {
user_id: String,
},
#[error("storage error: {message}")]
Internal {
message: String,
#[source]
source: Option<Box<dyn std::error::Error + Send + Sync>>,
},
#[error("connection error: {message}")]
Connection {
message: String,
#[source]
source: Option<Box<dyn std::error::Error + Send + Sync>>,
},
#[error("validation error: {0}")]
Validation(#[from] attuned_core::ValidationError),
}
impl StoreError {
pub fn internal(message: impl Into<String>) -> Self {
Self::Internal {
message: message.into(),
source: None,
}
}
pub fn internal_with_source(
message: impl Into<String>,
source: impl std::error::Error + Send + Sync + 'static,
) -> Self {
Self::Internal {
message: message.into(),
source: Some(Box::new(source)),
}
}
pub fn connection(message: impl Into<String>) -> Self {
Self::Connection {
message: message.into(),
source: None,
}
}
}