distributed_config/
error.rs1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, ConfigError>;
7
8#[derive(Debug, Error)]
10pub enum ConfigError {
11 #[error("Configuration file error: {0}")]
13 FileError(#[from] std::io::Error),
14
15 #[error("Serialization error: {0}")]
17 SerializationError(#[from] serde_json::Error),
18
19 #[error("YAML parsing error: {0}")]
21 YamlError(#[from] serde_yaml::Error),
22
23 #[error("TOML parsing error: {0}")]
25 TomlError(#[from] toml::de::Error),
26
27 #[error("Configuration key not found: {key}")]
29 KeyNotFound { key: String },
30
31 #[error("Type conversion error: cannot convert {from} to {to}")]
33 TypeConversion { from: String, to: String },
34
35 #[error("Schema validation error: {0}")]
37 ValidationError(String),
38
39 #[error("Network error: {0}")]
41 NetworkError(#[from] reqwest::Error),
42
43 #[error("Authentication error: {0}")]
45 AuthenticationError(String),
46
47 #[error("Source initialization error: {0}")]
49 SourceInitializationError(String),
50
51 #[error("Watcher error: {0}")]
53 WatcherError(String),
54
55 #[error("File system error: {0}")]
57 FileSystemError(#[from] notify::Error),
58
59 #[cfg(feature = "redis-backend")]
61 #[error("Redis error: {0}")]
62 RedisError(#[from] redis::RedisError),
63
64 #[cfg(feature = "etcd-backend")]
66 #[error("Etcd error: {0}")]
67 EtcdError(#[from] etcd_client::Error),
68
69 #[error("Lock timeout: failed to acquire lock within {timeout_ms}ms")]
71 LockTimeout { timeout_ms: u64 },
72
73 #[error("Configuration conflict: {0}")]
75 ConflictError(String),
76
77 #[error("Configuration error: {0}")]
79 Other(String),
80}
81
82impl ConfigError {
83 pub fn validation_error<S: Into<String>>(msg: S) -> Self {
85 ConfigError::ValidationError(msg.into())
86 }
87
88 pub fn auth_error<S: Into<String>>(msg: S) -> Self {
90 ConfigError::AuthenticationError(msg.into())
91 }
92
93 pub fn source_init_error<S: Into<String>>(msg: S) -> Self {
95 ConfigError::SourceInitializationError(msg.into())
96 }
97
98 pub fn watcher_error<S: Into<String>>(msg: S) -> Self {
100 ConfigError::WatcherError(msg.into())
101 }
102
103 pub fn conflict_error<S: Into<String>>(msg: S) -> Self {
105 ConfigError::ConflictError(msg.into())
106 }
107
108 pub fn other<S: Into<String>>(msg: S) -> Self {
110 ConfigError::Other(msg.into())
111 }
112}
113
114impl From<anyhow::Error> for ConfigError {
115 fn from(err: anyhow::Error) -> Self {
116 ConfigError::Other(err.to_string())
117 }
118}
119
120impl From<jsonschema::ValidationError<'_>> for ConfigError {
121 fn from(err: jsonschema::ValidationError<'_>) -> Self {
122 ConfigError::ValidationError(err.to_string())
123 }
124}