1use thiserror::Error;
6
7#[derive(Debug, Error)]
9pub enum StorageError {
10 #[error("Database error: {0}")]
12 DatabaseError(String),
13
14 #[error("RocksDB error: {0}")]
16 RocksDbError(#[from] rocksdb::Error),
17
18 #[error("Serialization error: {0}")]
20 SerializationError(String),
21
22 #[error("Deserialization error: {0}")]
24 DeserializationError(String),
25
26 #[error("Key not found: {0}")]
28 KeyNotFound(String),
29
30 #[error("Block not found: {0}")]
32 BlockNotFound(String),
33
34 #[error("Account not found: {0}")]
36 AccountNotFound(String),
37
38 #[error("Invalid state root: expected {expected}, got {actual}")]
40 InvalidStateRoot { expected: String, actual: String },
41
42 #[error("Merkle proof verification failed")]
44 InvalidMerkleProof,
45
46 #[error("Snapshot not found at height {0}")]
48 SnapshotNotFound(u64),
49
50 #[error("Invalid snapshot data: {0}")]
52 InvalidSnapshot(String),
53
54 #[error("Column family not found: {0}")]
56 ColumnFamilyNotFound(String),
57
58 #[error("IO error: {0}")]
60 IoError(#[from] std::io::Error),
61
62 #[error("Invalid key format: {0}")]
64 InvalidKey(String),
65
66 #[error("Invalid value format: {0}")]
68 InvalidValue(String),
69
70 #[error("Transaction rollback failed: {0}")]
72 RollbackFailed(String),
73
74 #[error("Transaction commit failed: {0}")]
76 CommitFailed(String),
77
78 #[error("Concurrent modification detected")]
80 ConcurrentModification,
81
82 #[error("Storage capacity exceeded")]
84 CapacityExceeded,
85
86 #[error("{0}")]
88 Generic(String),
89}
90
91pub type Result<T> = std::result::Result<T, StorageError>;
93
94impl From<bincode::Error> for StorageError {
95 fn from(err: bincode::Error) -> Self {
96 StorageError::SerializationError(err.to_string())
97 }
98}
99
100impl From<serde_json::Error> for StorageError {
101 fn from(err: serde_json::Error) -> Self {
102 StorageError::SerializationError(err.to_string())
103 }
104}