agent_config/error/
config_error.rs1use std::{io, path::PathBuf};
2
3#[derive(Debug, thiserror::Error)]
5pub enum ConfigError {
6 #[error("Failed to access configuration path '{path}': {source}")]
7 Io {
8 path: PathBuf,
9 #[source]
10 source: io::Error,
11 },
12
13 #[error("Invalid TOML in configuration file '{path}': {source}")]
14 Parse {
15 path: PathBuf,
16 #[source]
17 source: toml::de::Error,
18 },
19
20 #[error("Invalid {kind} configuration at {path:?}: {message}")]
21 Invalid {
22 kind: String,
23 path: Option<PathBuf>,
24 message: String,
25 },
26
27 #[error("Duplicate {kind} '{name}' at {path:?}")]
28 Duplicate {
29 kind: String,
30 name: String,
31 path: Option<PathBuf>,
32 },
33
34 #[error("No {kind} configuration files found in '{path}'")]
35 NoFilesFound { kind: String, path: PathBuf },
36}
37
38impl ConfigError {
39 pub fn invalid(
40 kind: impl Into<String>,
41 path: Option<impl Into<PathBuf>>,
42 message: impl Into<String>,
43 ) -> Self {
44 Self::Invalid {
45 kind: kind.into(),
46 path: path.map(Into::into),
47 message: message.into(),
48 }
49 }
50
51 pub fn duplicate(
52 kind: impl Into<String>,
53 name: impl Into<String>,
54 path: Option<impl Into<PathBuf>>,
55 ) -> Self {
56 Self::Duplicate {
57 kind: kind.into(),
58 name: name.into(),
59 path: path.map(Into::into),
60 }
61 }
62
63 pub fn no_files(kind: impl Into<String>, path: impl Into<PathBuf>) -> Self {
64 Self::NoFilesFound {
65 kind: kind.into(),
66 path: path.into(),
67 }
68 }
69}