#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("{0}")]
Json(String),
#[error("error in '{name}' fetcher: {error}")]
Fetcher { name: String, error: String },
#[error("error in '{fetcher}' matcher: {error}")]
Matcher { fetcher: String, error: String },
#[error("unknown operator '{0}'")]
UnknownOperator(String),
#[error("error in '{name}' operator: {error}")]
Operator { name: String, error: String },
#[error(transparent)]
Regex(#[from] regex::Error),
#[error(transparent)]
IpAddress(#[from] std::net::AddrParseError),
#[error(transparent)]
IpSubnet(#[from] ipnet::AddrParseError),
}
impl Error {
pub(crate) fn json(error: impl ToString) -> Self {
Error::Json(error.to_string())
}
pub(crate) fn fetcher(name: &str, error: impl ToString) -> Self {
Error::Fetcher {
name: name.to_string(),
error: error.to_string(),
}
}
pub(crate) fn matcher(fetcher: &str, error: impl ToString) -> Self {
Error::Matcher {
fetcher: fetcher.to_string(),
error: error.to_string(),
}
}
pub(crate) fn operator(name: &str, error: impl ToString) -> Self {
Error::Operator {
name: name.to_string(),
error: error.to_string(),
}
}
}