use thiserror::Error;
#[derive(Debug, Error)]
pub enum StorageError {
#[error("Database error: {0}")]
DatabaseError(String),
#[error("RocksDB error: {0}")]
RocksDbError(#[from] rocksdb::Error),
#[error("Serialization error: {0}")]
SerializationError(String),
#[error("Deserialization error: {0}")]
DeserializationError(String),
#[error("Key not found: {0}")]
KeyNotFound(String),
#[error("Block not found: {0}")]
BlockNotFound(String),
#[error("Account not found: {0}")]
AccountNotFound(String),
#[error("Invalid state root: expected {expected}, got {actual}")]
InvalidStateRoot { expected: String, actual: String },
#[error("Merkle proof verification failed")]
InvalidMerkleProof,
#[error("Snapshot not found at height {0}")]
SnapshotNotFound(u64),
#[error("Invalid snapshot data: {0}")]
InvalidSnapshot(String),
#[error("Column family not found: {0}")]
ColumnFamilyNotFound(String),
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
#[error("Invalid key format: {0}")]
InvalidKey(String),
#[error("Invalid value format: {0}")]
InvalidValue(String),
#[error("Transaction rollback failed: {0}")]
RollbackFailed(String),
#[error("Transaction commit failed: {0}")]
CommitFailed(String),
#[error("Concurrent modification detected")]
ConcurrentModification,
#[error("Storage capacity exceeded")]
CapacityExceeded,
#[error("{0}")]
Generic(String),
}
pub type Result<T> = std::result::Result<T, StorageError>;
impl From<bincode::Error> for StorageError {
fn from(err: bincode::Error) -> Self {
StorageError::SerializationError(err.to_string())
}
}
impl From<serde_json::Error> for StorageError {
fn from(err: serde_json::Error) -> Self {
StorageError::SerializationError(err.to_string())
}
}