use std::fmt;
#[derive(Debug)]
#[non_exhaustive]
pub enum ConfigulatorError {
#[cfg(feature = "file")]
FileNotFound,
#[cfg(feature = "file")]
FileError(String),
ParseError { field: String, value: String, message: String },
ValidationError(Box<dyn std::error::Error + Send + Sync>),
#[cfg(feature = "cli")]
CLIError(String),
}
impl fmt::Display for ConfigulatorError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
#[cfg(feature = "file")]
Self::FileNotFound => write!(f, "config file not found"),
#[cfg(feature = "file")]
Self::FileError(msg) => write!(f, "file error: {msg}"),
Self::ParseError { field, value, message } => {
write!(f, "failed to parse field '{field}' value '{value}': {message}")
}
Self::ValidationError(err) => write!(f, "validation error: {err}"),
#[cfg(feature = "cli")]
Self::CLIError(msg) => write!(f, "CLI error: {msg}"),
}
}
}
impl std::error::Error for ConfigulatorError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::ValidationError(err) => Some(err.as_ref()),
#[allow(unreachable_patterns)]
_ => None,
}
}
}