Skip to content

Commit

Permalink
🔥 thiserror from crate
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Snaps <[email protected]>
  • Loading branch information
alexsnaps committed Nov 25, 2024
1 parent 7e85052 commit c23a9b0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion limitador/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ dashmap = "6.1"
serde = { version = "1", features = ["derive", "rc"] }
postcard = { version = "1.0.4", features = ["use-std"] }
serde_json = "1"
thiserror = "2"
async-trait = "0.1"
cfg-if = "1"
tracing = "0.1.40"
Expand Down
24 changes: 21 additions & 3 deletions limitador/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
use crate::storage::StorageErr;
use thiserror::Error;
use std::error::Error;
use std::fmt::{Display, Formatter};

#[derive(Error, Debug)]
#[derive(Debug)]
pub enum LimitadorError {
#[error("error while accessing the limits storage: {0:?}")]
Storage(StorageErr),
}

impl Display for LimitadorError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
LimitadorError::Storage(err) => {
write!(f, "error while accessing the limits storage: {err:?}")
}
}
}
}

impl Error for LimitadorError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
LimitadorError::Storage(err) => Some(err),
}
}
}

impl From<StorageErr> for LimitadorError {
fn from(e: StorageErr) -> Self {
Self::Storage(e)
Expand Down

0 comments on commit c23a9b0

Please sign in to comment.