mithril_aggregator/dependency_injection/
error.rs1use std::{error::Error, fmt::Display};
4
5use config::ConfigError;
6use mithril_common::StdError;
7
8pub type Result<T> = std::result::Result<T, DependenciesBuilderError>;
10
11#[derive(Debug)]
13pub enum DependenciesBuilderError {
14 Initialization {
16 message: String,
18
19 error: Option<StdError>,
21 },
22
23 MissingConfiguration(String),
25
26 InconsistentState(String),
29}
30
31impl Display for DependenciesBuilderError {
32 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 match self {
34 Self::Initialization { message, error } => {
35 if let Some(nested) = error {
36 write!(
37 f,
38 "Dependency initialization error: «{message}» with additional nested error: '{nested:?}'."
39 )
40 } else {
41 write!(f, "Dependency initialization error: «{message}».")
42 }
43 }
44 Self::MissingConfiguration(field) => {
45 write!(f, "Missing configuration setting '{field}'.")
46 }
47 Self::InconsistentState(message) => {
48 write!(f, "Inconsistent dependency state: '{message}'.")
49 }
50 }
51 }
52}
53
54impl Error for DependenciesBuilderError {}
55
56impl From<StdError> for DependenciesBuilderError {
57 fn from(value: StdError) -> Self {
58 DependenciesBuilderError::Initialization {
59 message: "subsystem error".to_string(),
60 error: Some(value),
61 }
62 }
63}
64
65impl From<ConfigError> for DependenciesBuilderError {
66 fn from(value: ConfigError) -> Self {
67 Self::MissingConfiguration(format!("{value}"))
68 }
69}