use thiserror::Error;
pub type Result<T> = std::result::Result<T, ForgeError>;
#[derive(Error, Debug)]
pub enum ForgeError {
#[error("configuration error: {0}")]
Config(String),
#[error("nomad error: {0}")]
Nomad(String),
#[error("storage error: {0}")]
Storage(String),
#[error("network error: {0}")]
Network(String),
#[error("consensus error: {0}")]
Consensus(String),
#[error("routing error: {0}")]
Routing(String),
#[error("job error: {0}")]
Job(String),
#[error("autoscaler error: {0}")]
Autoscaler(String),
#[error("metrics error: {0}")]
Metrics(String),
#[error("runtime error: {0}")]
Runtime(String),
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("internal error: {0}")]
Internal(String),
}
impl ForgeError {
pub fn config(msg: impl Into<String>) -> Self {
Self::Config(msg.into())
}
pub fn nomad(msg: impl Into<String>) -> Self {
Self::Nomad(msg.into())
}
pub fn storage(msg: impl Into<String>) -> Self {
Self::Storage(msg.into())
}
pub fn network(msg: impl Into<String>) -> Self {
Self::Network(msg.into())
}
pub fn job(msg: impl Into<String>) -> Self {
Self::Job(msg.into())
}
pub fn runtime(msg: impl Into<String>) -> Self {
Self::Runtime(msg.into())
}
pub fn metrics(msg: impl Into<String>) -> Self {
Self::Metrics(msg.into())
}
}
impl From<reqwest::Error> for ForgeError {
fn from(err: reqwest::Error) -> Self {
Self::Network(err.to_string())
}
}
impl From<prometheus::Error> for ForgeError {
fn from(err: prometheus::Error) -> Self {
Self::Metrics(err.to_string())
}
}