1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
use crate::{string, H256}; pub type Result<T> = ::core::result::Result<T, Error>; #[derive(Debug, Clone, PartialEq)] pub enum Error { MissingKey(usize, H256), CorruptedProof, EmptyProof, EmptyKeys, EmptyTree, IncorrectNumberOfLeaves { expected: usize, actual: usize }, Store(string::String), } impl core::fmt::Display for Error { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Error::MissingKey(height, key) => { write!(f, "Missing key at height {}, key {:?}", height, key)?; } Error::CorruptedProof => { write!(f, "Corrupted proof")?; } Error::EmptyProof => { write!(f, "Empty proof")?; } Error::EmptyKeys => { write!(f, "Empty keys")?; } Error::EmptyTree => { write!(f, "Empty tree")?; } Error::IncorrectNumberOfLeaves { expected, actual } => { write!( f, "Incorrect number of leaves, expected {} actual {}", expected, actual )?; } Error::Store(err_msg) => { write!(f, "Backend store error: {}", err_msg)?; } } Ok(()) } } #[cfg(feature = "std")] impl std::error::Error for Error {}