Skip to main content

miden_crypto/merkle/smt/large/storage/
error.rs

1use alloc::{boxed::Box, string::String};
2
3/// Errors returned by any `SmtStorage` implementation.
4///
5/// Categories:
6/// - Backend errors (DB/I/O)
7/// - Decode/length mismatches with expected/actual parameters
8/// - Unsupported operations
9/// - Higher-level value and subtree decode failures
10#[derive(Debug, thiserror::Error)]
11pub enum StorageError {
12    /// Backend I/O or database error (e.g., RocksDB).
13    #[error("backend error: {0}")]
14    Backend(#[from] Box<dyn core::error::Error + Send + Sync + 'static>),
15    /// Key bytes had the wrong length (e.g., leaf index key, subtree root key).
16    #[error("invalid key length: expected {expected} bytes, found {found}")]
17    BadKeyLen { expected: usize, found: usize },
18    /// Subtree key bytes had the wrong length (e.g., subtree root key).
19    #[error(
20        "invalid subtree key length at depth {depth}: expected {expected} bytes, found {found}"
21    )]
22    BadSubtreeKeyLen { depth: u8, expected: usize, found: usize },
23    /// Value/metadata bytes had the wrong length (e.g., leaf/entry counts).
24    #[error("invalid value length for {what}: expected {expected} bytes, found {found}")]
25    BadValueLen {
26        what: &'static str,
27        expected: usize,
28        found: usize,
29    },
30    /// Leaf-level error (e.g., too many entries).
31    #[error("leaf operation failed")]
32    Leaf(#[from] crate::merkle::smt::SmtLeafError),
33    /// Failed to (de)serialize a stored subtree blob.
34    #[error("failed to decode subtree")]
35    Subtree(#[from] crate::merkle::smt::SubtreeError),
36    /// The requested operation is not supported by this backend.
37    #[error("operation not supported: {0}")]
38    Unsupported(String),
39    /// Higher-level type (e.g., `Word`) failed to decode from bytes.
40    #[error("failed to decode value bytes")]
41    Value(#[from] crate::utils::DeserializationError),
42}