use std::path::PathBuf;
use crate::source::Format;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("configuration file not found: {}", .path.display())]
NotFound {
path: PathBuf,
},
#[error("failed to read configuration file {}: {source}", .path.display())]
Io {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("cannot detect configuration format of `{}` (expected .toml, .yaml, .yml or .json)", .path.display())]
UnknownExtension {
path: PathBuf,
},
#[error("{format} support is disabled; enable the `{feature}` feature of confy-rs")]
FeatureDisabled {
format: Format,
feature: &'static str,
},
#[error("failed to parse {} as {format}: {message}", display_origin(.origin))]
Parse {
origin: Option<PathBuf>,
format: Format,
message: String,
},
#[error("failed to deserialize configuration: {0}")]
Deserialize(#[source] serde_json::Error),
#[error("failed to serialize defaults layer: {0}")]
Defaults(#[source] serde_json::Error),
#[cfg(feature = "watch")]
#[error("failed to watch configuration files: {0}")]
Watch(#[from] notify::Error),
}
fn display_origin(origin: &Option<PathBuf>) -> String {
match origin {
Some(path) => path.display().to_string(),
None => "inline string".to_string(),
}
}