Skip to main content

tenzro_storage/
error.rs

1//! Error types for Tenzro Network storage layer
2//!
3//! This module defines error types used throughout the storage subsystem.
4
5use thiserror::Error;
6
7/// Storage-specific errors
8#[derive(Debug, Error)]
9pub enum StorageError {
10    /// Database error
11    #[error("Database error: {0}")]
12    DatabaseError(String),
13
14    /// RocksDB error
15    #[error("RocksDB error: {0}")]
16    RocksDbError(#[from] rocksdb::Error),
17
18    /// Serialization error
19    #[error("Serialization error: {0}")]
20    SerializationError(String),
21
22    /// Deserialization error
23    #[error("Deserialization error: {0}")]
24    DeserializationError(String),
25
26    /// Key not found
27    #[error("Key not found: {0}")]
28    KeyNotFound(String),
29
30    /// Block not found
31    #[error("Block not found: {0}")]
32    BlockNotFound(String),
33
34    /// Account not found
35    #[error("Account not found: {0}")]
36    AccountNotFound(String),
37
38    /// Invalid state root
39    #[error("Invalid state root: expected {expected}, got {actual}")]
40    InvalidStateRoot { expected: String, actual: String },
41
42    /// Merkle proof verification failed
43    #[error("Merkle proof verification failed")]
44    InvalidMerkleProof,
45
46    /// Snapshot not found
47    #[error("Snapshot not found at height {0}")]
48    SnapshotNotFound(u64),
49
50    /// Invalid snapshot data
51    #[error("Invalid snapshot data: {0}")]
52    InvalidSnapshot(String),
53
54    /// Column family not found
55    #[error("Column family not found: {0}")]
56    ColumnFamilyNotFound(String),
57
58    /// IO error
59    #[error("IO error: {0}")]
60    IoError(#[from] std::io::Error),
61
62    /// Invalid key format
63    #[error("Invalid key format: {0}")]
64    InvalidKey(String),
65
66    /// Invalid value format
67    #[error("Invalid value format: {0}")]
68    InvalidValue(String),
69
70    /// Transaction rollback failed
71    #[error("Transaction rollback failed: {0}")]
72    RollbackFailed(String),
73
74    /// Transaction commit failed
75    #[error("Transaction commit failed: {0}")]
76    CommitFailed(String),
77
78    /// Concurrent modification error
79    #[error("Concurrent modification detected")]
80    ConcurrentModification,
81
82    /// Storage capacity exceeded
83    #[error("Storage capacity exceeded")]
84    CapacityExceeded,
85
86    /// Generic error
87    #[error("{0}")]
88    Generic(String),
89}
90
91/// Result type for storage operations
92pub 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}