#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum MemoryError {
#[error("serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("[{backend}] {message}")]
Storage {
backend: &'static str,
message: String,
},
#[error("lock error: {0}")]
Lock(String),
#[error("task error: {0}")]
Task(String),
}
impl MemoryError {
#[must_use]
pub fn storage(backend: &'static str, message: impl Into<String>) -> Self {
Self::Storage {
backend,
message: message.into(),
}
}
#[must_use]
pub const fn is_retryable(&self) -> bool {
matches!(self, Self::Lock(_) | Self::Task(_))
}
}
#[cfg(feature = "memory-sqlite")]
impl From<rusqlite::Error> for MemoryError {
fn from(e: rusqlite::Error) -> Self {
Self::storage("sqlite", e.to_string())
}
}