use std::fmt;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("unknown format {0:?}")]
UnknownFormat(String),
#[error("invalid pattern for {name:?}: {message}")]
InvalidPattern {
name: String,
message: String,
},
#[error("ruleset: {0}")]
Ruleset(String),
#[error("config: {0}")]
Config(String),
#[error("{name}: {message}")]
Detector {
name: String,
message: String,
},
#[error(transparent)]
Format(#[from] FormatError),
#[error(transparent)]
Io(#[from] std::io::Error),
}
#[derive(Debug, thiserror::Error)]
#[error("{format}: {message}")]
pub struct FormatError {
format: String,
message: String,
}
impl FormatError {
pub fn new(format: impl Into<String>, message: impl fmt::Display) -> Self {
Self {
format: format.into(),
message: message.to_string(),
}
}
pub fn format(&self) -> &str {
&self.format
}
pub fn message(&self) -> &str {
&self.message
}
}