mirror of https://github.com/vacp2p/pmtree.git
Merge pull request #8 from Rate-Limiting-Nullifier/custom-unknown-error
Custom errors for users
This commit is contained in:
commit
cbb966da2e
|
@ -10,6 +10,8 @@ pub mod database;
|
|||
pub mod hasher;
|
||||
pub mod tree;
|
||||
|
||||
use std::fmt::{Debug, Display};
|
||||
|
||||
pub use database::*;
|
||||
pub use hasher::*;
|
||||
pub use tree::MerkleTree;
|
||||
|
@ -25,12 +27,14 @@ pub enum TreeErrorKind {
|
|||
MerkleTreeIsFull,
|
||||
InvalidKey,
|
||||
IndexOutOfBounds,
|
||||
CustomError(String),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum DatabaseErrorKind {
|
||||
CannotLoadDatabase,
|
||||
DatabaseExists,
|
||||
CustomError(String),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -39,13 +43,16 @@ pub enum PmtreeErrorKind {
|
|||
DatabaseError(DatabaseErrorKind),
|
||||
/// Error in tree
|
||||
TreeError(TreeErrorKind),
|
||||
/// Custom error
|
||||
CustomError(String),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for PmtreeErrorKind {
|
||||
impl Display for PmtreeErrorKind {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
PmtreeErrorKind::DatabaseError(e) => write!(f, "Database error: {e:?}"),
|
||||
PmtreeErrorKind::TreeError(e) => write!(f, "Tree error: {e:?}"),
|
||||
PmtreeErrorKind::CustomError(e) => write!(f, "Custom error: {e:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue