use std::fmt;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("io: {0}")]
Io(#[from] std::io::Error),
#[error("toml: {0}")]
TomlParse(String),
#[error("json: {0}")]
JsonParse(String),
#[error("missing dependency: {name}{}", .hint.as_deref().map(|h| format!(" ({h})")).unwrap_or_default())]
MissingDependency {
name: String,
hint: Option<String>,
},
#[error("contract violation: {0}")]
ContractViolation(String),
#[error("{0}")]
Other(String),
}
impl Error {
pub fn other(msg: impl fmt::Display) -> Self {
Self::Other(msg.to_string())
}
pub fn contract(msg: impl fmt::Display) -> Self {
Self::ContractViolation(msg.to_string())
}
}
impl From<toml::de::Error> for Error {
fn from(value: toml::de::Error) -> Self {
Self::TomlParse(value.to_string())
}
}
impl From<serde_json::Error> for Error {
fn from(value: serde_json::Error) -> Self {
Self::JsonParse(value.to_string())
}
}