mithril_aggregator/dependency_injection/
error.rsuse std::{error::Error, fmt::Display};
use config::ConfigError;
use mithril_common::StdError;
pub type Result<T> = std::result::Result<T, DependenciesBuilderError>;
#[derive(Debug)]
pub enum DependenciesBuilderError {
Initialization {
message: String,
error: Option<StdError>,
},
MissingConfiguration(String),
InconsistentState(String),
}
impl Display for DependenciesBuilderError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Initialization { message, error } => {
if let Some(nested) = error {
write!(f, "Dependency initialization error: «{message}» with additional nested error: '{nested:?}'.")
} else {
write!(f, "Dependency initialization error: «{message}».")
}
}
Self::MissingConfiguration(field) => {
write!(f, "Missing configuration setting '{field}'.")
}
Self::InconsistentState(message) => {
write!(f, "Inconsistent dependency state: '{message}'.")
}
}
}
}
impl Error for DependenciesBuilderError {}
impl From<StdError> for DependenciesBuilderError {
fn from(value: StdError) -> Self {
DependenciesBuilderError::Initialization {
message: "subsystem error".to_string(),
error: Some(value),
}
}
}
impl From<ConfigError> for DependenciesBuilderError {
fn from(value: ConfigError) -> Self {
Self::MissingConfiguration(format!("{value}"))
}
}