nam_sparse_merkle_tree/
error.rs1use crate::{string, H256};
2
3pub type Result<T> = ::core::result::Result<T, Error>;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub enum Error {
7 MissingKey(usize, H256),
8 CorruptedProof,
9 EmptyProof,
10 EmptyKeys,
11 IncorrectNumberOfLeaves { expected: usize, actual: usize },
12 Store(string::String),
13 CorruptedStack,
14 NonSiblings,
15 InvalidCode(u8),
16 NonMergableRange,
17 ExistenceProof,
18 NonExistenceProof,
19 KeyTooLarge,
20}
21
22impl core::fmt::Display for Error {
23 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
24 match self {
25 Error::MissingKey(height, key) => {
26 write!(f, "Missing key at height {}, key {:?}", height, key)?;
27 }
28 Error::CorruptedProof => {
29 write!(f, "Corrupted proof")?;
30 }
31 Error::EmptyProof => {
32 write!(f, "Empty proof")?;
33 }
34 Error::EmptyKeys => {
35 write!(f, "Empty keys")?;
36 }
37 Error::IncorrectNumberOfLeaves { expected, actual } => {
38 write!(
39 f,
40 "Incorrect number of leaves, expected {} actual {}",
41 expected, actual
42 )?;
43 }
44 Error::Store(err_msg) => {
45 write!(f, "Backend store error: {}", err_msg)?;
46 }
47 Error::CorruptedStack => {
48 write!(f, "Corrupted compiled proof stack")?;
49 }
50 Error::NonSiblings => {
51 write!(f, "Merging non-siblings in compiled stack")?;
52 }
53 Error::InvalidCode(code) => {
54 write!(f, "Invalid compiled proof code: {}", code)?;
55 }
56 Error::NonMergableRange => {
57 write!(f, "Ranges can not be merged")?;
58 }
59 Error::ExistenceProof => {
60 write!(f, "Try to get ExistenceProof for non existing value")?;
61 }
62 Error::NonExistenceProof => {
63 write!(f, "Try to get NonExistenceProof for the existing value")?;
64 }
65 Error::KeyTooLarge => {
66 write!(f, "Provided key has too many bytes")?;
67 }
68 }
69 Ok(())
70 }
71}
72
73#[cfg(feature = "std")]
74impl std::error::Error for Error {}