-
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.
Deal with syntax error of conditions
Signed-off-by: Alex Snaps <alex@wcgw.dev>
- Loading branch information
Showing
13 changed files
with
237 additions
and
132 deletions.
There are no files selected for viewing
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,32 +1,51 @@ | ||
use crate::limit::ConditionParsingError; | ||
use crate::storage::StorageErr; | ||
use std::convert::Infallible; | ||
use std::error::Error; | ||
use std::fmt::{Display, Formatter}; | ||
|
||
#[derive(Debug)] | ||
pub enum LimitadorError { | ||
Storage(StorageErr), | ||
StorageError(StorageErr), | ||
InterpreterError(ConditionParsingError), | ||
} | ||
|
||
impl Display for LimitadorError { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
LimitadorError::Storage(err) => { | ||
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::Storage(err) => Some(err), | ||
LimitadorError::StorageError(err) => Some(err), | ||
LimitadorError::InterpreterError(err) => Some(err), | ||
} | ||
} | ||
} | ||
|
||
impl From<StorageErr> for LimitadorError { | ||
fn from(e: StorageErr) -> Self { | ||
Self::Storage(e) | ||
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) | ||
} | ||
} |
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
Oops, something went wrong.