Merge pull request #8 from Rate-Limiting-Nullifier/custom-unknown-error

Custom errors for users
This commit is contained in:
Magamedrasul Ibragimov 2023-04-25 17:16:57 +04:00 committed by GitHub
commit cbb966da2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -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:?}"),
}
}
}