1use std::path::PathBuf;
4
5use crate::source::Format;
6
7#[derive(Debug, thiserror::Error)]
9#[non_exhaustive]
10pub enum Error {
11 #[error("configuration file not found: {}", .path.display())]
13 NotFound {
14 path: PathBuf,
16 },
17
18 #[error("failed to read configuration file {}: {source}", .path.display())]
20 Io {
21 path: PathBuf,
23 #[source]
25 source: std::io::Error,
26 },
27
28 #[error("cannot detect configuration format of `{}` (expected .toml, .yaml, .yml or .json)", .path.display())]
30 UnknownExtension {
31 path: PathBuf,
33 },
34
35 #[error("{format} support is disabled; enable the `{feature}` feature of confy-rs")]
37 FeatureDisabled {
38 format: Format,
40 feature: &'static str,
42 },
43
44 #[error("failed to parse {} as {format}: {message}", display_origin(.origin))]
46 Parse {
47 origin: Option<PathBuf>,
49 format: Format,
51 message: String,
53 },
54
55 #[error("failed to deserialize configuration: {0}")]
57 Deserialize(#[source] serde_json::Error),
58
59 #[error("failed to serialize defaults layer: {0}")]
61 Defaults(#[source] serde_json::Error),
62
63 #[cfg(feature = "watch")]
65 #[error("failed to watch configuration files: {0}")]
66 Watch(#[from] notify::Error),
67}
68
69fn display_origin(origin: &Option<PathBuf>) -> String {
70 match origin {
71 Some(path) => path.display().to_string(),
72 None => "inline string".to_string(),
73 }
74}