restricted_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 MissingBranch(H256),
8 MissingLeaf(H256),
9 CorruptedProof,
10 EmptyProof,
11 EmptyKeys,
12 IncorrectNumberOfLeaves { expected: usize, actual: usize },
13 Store(string::String),
14 ForbidZeroValueLeaf,
15 CorruptedStack,
16 NonSiblings,
17 InvalidCode(u8),
18 NonMergableRange,
19}
20
21impl core::fmt::Display for Error {
22 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
23 match self {
24 Error::MissingBranch(node) => {
25 write!(f, "Corrupted store, missing branch {:?}", node)?;
26 }
27 Error::MissingLeaf(node) => {
28 write!(f, "Corrupted store, missing leaf {:?}", node)?;
29 }
30 Error::CorruptedProof => {
31 write!(f, "Corrupted proof")?;
32 }
33 Error::EmptyProof => {
34 write!(f, "Empty proof")?;
35 }
36 Error::EmptyKeys => {
37 write!(f, "Empty keys")?;
38 }
39 Error::IncorrectNumberOfLeaves { expected, actual } => {
40 write!(
41 f,
42 "Incorrect number of leaves, expected {} actual {}",
43 expected, actual
44 )?;
45 }
46 Error::Store(err_msg) => {
47 write!(f, "Backend store error: {}", err_msg)?;
48 }
49 Error::CorruptedStack => {
50 write!(f, "Corrupted compiled proof stack")?;
51 }
52 Error::ForbidZeroValueLeaf => {
53 write!(f, "Zero value leaf is not allowed to verify proof")?;
54 }
55 Error::NonSiblings => {
56 write!(f, "Merging non-siblings in compiled stack")?;
57 }
58 Error::InvalidCode(code) => {
59 write!(f, "Invalid compiled proof code: {}", code)?;
60 }
61 Error::NonMergableRange => {
62 write!(f, "Ranges can not be merged")?;
63 }
64 }
65 Ok(())
66 }
67}
68
69#[cfg(feature = "std")]
70impl std::error::Error for Error {}