use std::fmt::{self};
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum EngineError {
InvalidCharacterInRegex,
OperationTimeOutError,
AutomatonHasTooManyStates,
RegexSyntaxError(String),
ConditionInvalidRange,
InvalidRepetitionBounds(u32, u32),
IncompatibleSpanningSet,
DeterministicAutomatonRequired,
UnsupportedRegexFeature(String),
RegexTooDeeplyNested(usize),
}
impl fmt::Display for EngineError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
EngineError::InvalidCharacterInRegex => {
write!(f, "invalid character used in regex")
}
EngineError::OperationTimeOutError => write!(f, "the operation timed out"),
EngineError::AutomatonHasTooManyStates => {
write!(f, "the automaton has too many states")
}
EngineError::RegexSyntaxError(err) => write!(f, "invalid regex syntax: {err}"),
EngineError::ConditionInvalidRange => write!(
f,
"the provided range cannot be built from the spanning set"
),
EngineError::InvalidRepetitionBounds(min, max) => write!(
f,
"the repetition maximum ({max}) is below its minimum ({min})"
),
EngineError::IncompatibleSpanningSet => write!(
f,
"the condition does not match the spanning set it is evaluated against"
),
EngineError::DeterministicAutomatonRequired => write!(
f,
"the operation requires a deterministic automaton, and implicit determinization is disabled by the execution profile"
),
EngineError::UnsupportedRegexFeature(feature) => {
write!(f, "unsupported regex feature: {feature}")
}
EngineError::RegexTooDeeplyNested(limit) => write!(
f,
"the regular expression is nested more than {limit} levels deep"
),
}
}
}
impl std::error::Error for EngineError {}