use std::fmt;
use forbidden_regex::CompileError;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum LoadError {
NoRules,
UnsupportedFlag {
index: usize,
flag: char,
},
Compile {
index: usize,
reason: CompileError,
},
Precompiled {
reason: CompileError,
},
}
impl fmt::Display for LoadError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
LoadError::NoRules => {
return write!(f, "no rules loaded")
}
LoadError::UnsupportedFlag { index, flag } => {
return write!(
f,
"rule {index}: unsupported flag '{flag}'; only 'm' and 'x' are accepted as no-ops",
)
}
LoadError::Compile { index, reason } => {
return write!(f, "rule {index}: {reason}")
}
LoadError::Precompiled { reason } => {
return write!(f, "precompiled ruleset failed to load: {reason}")
}
}
}
}
impl std::error::Error for LoadError {}
#[cfg(test)]
#[path = "error_tests.rs"]
mod error_tests;