41 lines
968 B
Rust
41 lines
968 B
Rust
|
|
use thiserror::Error;
|
||
|
|
|
||
|
|
/// Errors that can occur in storage operations.
|
||
|
|
#[derive(Debug, Error)]
|
||
|
|
pub enum StorageError {
|
||
|
|
#[error("not found: {0}")]
|
||
|
|
NotFound(String),
|
||
|
|
|
||
|
|
#[error("already exists: {0}")]
|
||
|
|
AlreadyExists(String),
|
||
|
|
|
||
|
|
#[error("I/O error: {0}")]
|
||
|
|
IoError(#[from] std::io::Error),
|
||
|
|
|
||
|
|
#[error("serialization error: {0}")]
|
||
|
|
SerializationError(String),
|
||
|
|
|
||
|
|
#[error("conflict detected: {0}")]
|
||
|
|
ConflictError(String),
|
||
|
|
}
|
||
|
|
|
||
|
|
impl From<serde_json::Error> for StorageError {
|
||
|
|
fn from(e: serde_json::Error) -> Self {
|
||
|
|
StorageError::SerializationError(e.to_string())
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl From<bson::de::Error> for StorageError {
|
||
|
|
fn from(e: bson::de::Error) -> Self {
|
||
|
|
StorageError::SerializationError(e.to_string())
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl From<bson::ser::Error> for StorageError {
|
||
|
|
fn from(e: bson::ser::Error) -> Self {
|
||
|
|
StorageError::SerializationError(e.to_string())
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
pub type StorageResult<T> = Result<T, StorageError>;
|