From c23a9b01cd9a4a5d181a8ec1f8a6b8a412db8daa Mon Sep 17 00:00:00 2001 From: Alex Snaps Date: Mon, 25 Nov 2024 12:41:31 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20thiserror=20from=20crate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Alex Snaps --- Cargo.lock | 1 - limitador/Cargo.toml | 1 - limitador/src/errors.rs | 24 +++++++++++++++++++++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5b7ed5c2..ab170a96 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1844,7 +1844,6 @@ dependencies = [ "serde_json", "serial_test", "tempfile", - "thiserror 2.0.3", "tokio", "tokio-stream", "tonic 0.12.3", diff --git a/limitador/Cargo.toml b/limitador/Cargo.toml index 7dc687aa..d9240b5f 100644 --- a/limitador/Cargo.toml +++ b/limitador/Cargo.toml @@ -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" diff --git a/limitador/src/errors.rs b/limitador/src/errors.rs index 2bd4e98c..d5204b62 100644 --- a/limitador/src/errors.rs +++ b/limitador/src/errors.rs @@ -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 for LimitadorError { fn from(e: StorageErr) -> Self { Self::Storage(e)