#[derive(Debug, thiserror::Error)]
pub enum ConfigError {
#[error("configuration not found: {0}")]
NotFound(String),
#[error("failed to parse configuration: {0}")]
Parse(String),
#[error("file error: {0}")]
#[cfg(feature = "files")]
File(#[from] cfgmatic_files::FileError),
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("value not found at path: {0}")]
ValueNotFound(String),
#[error("serialization error: {0}")]
Serialization(String),
#[error("validation error: {0}")]
Validation(String),
#[error("environment variable error: {0}")]
EnvVar(String),
#[error("multiple errors: {0:?}")]
Multiple(Vec<Self>),
}
pub type Result<T> = std::result::Result<T, ConfigError>;
pub trait ConfigFields {
fn load_from_env(&mut self, prefix: Option<&str>) -> Result<()>;
fn env_prefix() -> &'static str;
}
impl ConfigError {
pub fn parse(msg: impl Into<String>) -> Self {
Self::Parse(msg.into())
}
pub fn not_found(msg: impl Into<String>) -> Self {
Self::NotFound(msg.into())
}
pub fn validation(msg: impl Into<String>) -> Self {
Self::Validation(msg.into())
}
}