Files
smartdb/rust/crates/rustdb-storage/src/error.rs
T

50 lines
1.2 KiB
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),
#[error("corrupt record: {0}")]
CorruptRecord(String),
#[error("checksum mismatch: expected 0x{expected:08X}, got 0x{actual:08X}")]
ChecksumMismatch { expected: u32, actual: u32 },
#[error("WAL error: {0}")]
WalError(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>;