pub type Result<T> = std::result::Result<T, InquisitorError>;
#[derive(Debug)]
pub enum InquisitorError {
DurationParseError,
SignalHandlerCouldNotBeSet(ctrlc::Error),
HistogramCouldNotBeCreated(hdrhistogram::CreationError),
InvalidRegex(regex::Error),
CouldNotOpenFile(std::io::Error, String),
CouldNotReadFile(std::io::Error, String),
CouldNotConvertCert(reqwest::Error, String),
FailedToCreateClient(reqwest::Error),
FailedToGetTimeInterval(std::time::SystemTimeError),
FailedToBuildAsyncRuntime(tokio::io::Error),
}
impl std::fmt::Display for InquisitorError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
match self {
Self::DurationParseError => write!(f, "Failed to parse duration"),
Self::SignalHandlerCouldNotBeSet(e) => write!(f, "Could not set signal handler: {e}"),
Self::HistogramCouldNotBeCreated(e) => {
write!(f, "Could not create histogram for response times: {e}")
}
Self::InvalidRegex(e) => write!(f, "Invalid regex: {e}"),
Self::CouldNotOpenFile(e, file) => write!(f, "Could not open file '{file}': {e}"),
Self::CouldNotReadFile(e, file) => write!(f, "Could not read file '{file}': {e}"),
Self::CouldNotConvertCert(e, file) => {
write!(f, "Could not convert file '{file}' to PEM certificate: {e}")
}
Self::FailedToCreateClient(e) => write!(f, "Failed to build HTTP client: {e}"),
Self::FailedToGetTimeInterval(e) => write!(f, "Failed to get elapsed time: {e}"),
Self::FailedToBuildAsyncRuntime(e) => write!(f, "Failed to crate async runtime: {e}"),
}
}
}
impl std::error::Error for InquisitorError {}
impl From<ctrlc::Error> for InquisitorError {
fn from(e: ctrlc::Error) -> Self {
Self::SignalHandlerCouldNotBeSet(e)
}
}
impl From<hdrhistogram::CreationError> for InquisitorError {
fn from(e: hdrhistogram::CreationError) -> Self {
Self::HistogramCouldNotBeCreated(e)
}
}
impl From<regex::Error> for InquisitorError {
fn from(e: regex::Error) -> Self {
Self::InvalidRegex(e)
}
}
impl From<tokio::io::Error> for InquisitorError {
fn from(e: tokio::io::Error) -> Self {
Self::FailedToBuildAsyncRuntime(e)
}
}