use std::fmt;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("configuration error: {0}")]
Config(String),
#[error("failed to parse {what} at log index {index}: {reason}")]
Parse {
what: String,
index: usize,
reason: String,
},
#[error("simulation failure: {0}")]
Simulation(String),
#[error("baseline error: {0}")]
Baseline(String),
#[error("execution backend `{0}` is not implemented in this build")]
BackendUnimplemented(String),
#[error("i/o error: {0}")]
Io(#[from] std::io::Error),
#[error("toml error: {0}")]
Toml(String),
#[cfg(feature = "json")]
#[error("json error: {0}")]
Json(#[from] serde_json::Error),
}
impl Error {
pub fn parse(what: impl fmt::Display, index: usize, reason: impl fmt::Display) -> Self {
Self::Parse {
what: what.to_string(),
index,
reason: reason.to_string(),
}
}
}
impl From<toml::de::Error> for Error {
fn from(e: toml::de::Error) -> Self {
Self::Toml(e.to_string())
}
}