use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("Config error: {0}")]
Config(String),
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("Network error: {0}")]
Network(String),
#[error("Docker error: {0}")]
Docker(String),
#[error("Validation error: {0}")]
Validation(String),
#[error("{0}")]
Other(String),
}
pub type Result<T> = std::result::Result<T, Error>;
impl Error {
pub fn config(msg: impl Into<String>) -> Self {
Self::Config(msg.into())
}
pub fn network(msg: impl Into<String>) -> Self {
Self::Network(msg.into())
}
pub fn docker(msg: impl Into<String>) -> Self {
Self::Docker(msg.into())
}
pub fn validation(msg: impl Into<String>) -> Self {
Self::Validation(msg.into())
}
pub fn other(msg: impl Into<String>) -> Self {
Self::Other(msg.into())
}
}
impl From<String> for Error {
fn from(s: String) -> Self {
Self::Other(s)
}
}
impl From<&str> for Error {
fn from(s: &str) -> Self {
Self::Other(s.to_owned())
}
}
impl From<reqwest::Error> for Error {
fn from(e: reqwest::Error) -> Self {
Self::Network(e.to_string())
}
}