-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #386 from Kuadrant/error_types
Proper `Error` types for the crate
- Loading branch information
Showing
23 changed files
with
934 additions
and
614 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,51 @@ | ||
use crate::limit::ConditionParsingError; | ||
use crate::storage::StorageErr; | ||
use thiserror::Error; | ||
use std::convert::Infallible; | ||
use std::error::Error; | ||
use std::fmt::{Display, Formatter}; | ||
|
||
#[derive(Error, Debug, Eq, PartialEq)] | ||
#[derive(Debug)] | ||
pub enum LimitadorError { | ||
#[error("error while accessing the limits storage: {0:?}")] | ||
Storage(String), | ||
StorageError(StorageErr), | ||
InterpreterError(ConditionParsingError), | ||
} | ||
|
||
impl Display for LimitadorError { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
LimitadorError::StorageError(err) => { | ||
write!(f, "error while accessing the limits storage: {err:?}") | ||
} | ||
LimitadorError::InterpreterError(err) => { | ||
write!(f, "error parsing condition: {err:?}") | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl Error for LimitadorError { | ||
fn source(&self) -> Option<&(dyn Error + 'static)> { | ||
match self { | ||
LimitadorError::StorageError(err) => Some(err), | ||
LimitadorError::InterpreterError(err) => Some(err), | ||
} | ||
} | ||
} | ||
|
||
impl From<StorageErr> for LimitadorError { | ||
fn from(e: StorageErr) -> Self { | ||
Self::Storage(e.msg().to_owned()) | ||
Self::StorageError(e) | ||
} | ||
} | ||
|
||
impl From<ConditionParsingError> for LimitadorError { | ||
fn from(err: ConditionParsingError) -> Self { | ||
LimitadorError::InterpreterError(err) | ||
} | ||
} | ||
|
||
impl From<Infallible> for LimitadorError { | ||
fn from(value: Infallible) -> Self { | ||
unreachable!("unexpected infallible value: {:?}", value) | ||
} | ||
} |
Oops, something went wrong.