openapi_nexus_config/
errors.rs1use std::error::Error;
4use std::fmt;
5use std::io;
6use std::path::PathBuf;
7
8#[derive(Debug)]
10pub enum ConfigError {
11 FileRead { path: PathBuf, source: io::Error },
13 FileParse {
15 path: PathBuf,
16 source: toml::de::Error,
17 },
18 ParseOverrides(String),
20 Validation(String),
22}
23
24impl fmt::Display for ConfigError {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 match self {
27 ConfigError::FileRead { path, source } => {
28 write!(f, "Failed to read config file at {:?}: {}", path, source)
29 }
30 ConfigError::FileParse { path, source } => {
31 write!(f, "Failed to parse config file at {:?}: {}", path, source)
32 }
33 ConfigError::ParseOverrides(msg) => {
34 write!(f, "Failed to parse generator config overrides: {}", msg)
35 }
36 ConfigError::Validation(msg) => {
37 write!(f, "Configuration validation error: {}", msg)
38 }
39 }
40 }
41}
42
43impl Error for ConfigError {
44 fn source(&self) -> Option<&(dyn Error + 'static)> {
45 match self {
46 ConfigError::FileRead { source, .. } => Some(source),
47 ConfigError::FileParse { source, .. } => Some(source),
48 ConfigError::ParseOverrides(_) => None,
49 ConfigError::Validation(_) => None,
50 }
51 }
52}