Skip to content

Commit 7496699

Browse files
committed
fix: Future-proof for eventual origin tracking
It looks like we lose track of `origin` in a lot of cases when merging sources which makes actual `origin` tracking meaningless until that is fixed which looked non-trivial. Adding this field at least gives us more of an option to do it later.
1 parent da066d2 commit 7496699

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/error.rs

+20-3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ pub enum ConfigError {
8383
/// Error being extended with a path
8484
error: Box<ConfigError>,
8585

86+
/// The URI that references the source that the value came from.
87+
/// Example: `/path/to/config.json` or `Environment` or `etcd://localhost`
88+
// TODO: Why is this called Origin but FileParse has a uri field?
89+
origin: Option<String>,
90+
8691
/// The key in the configuration hash of this value (if available where the
8792
/// error is generated).
8893
key: Option<String>,
@@ -140,13 +145,15 @@ impl ConfigError {
140145
key: Some(key.into()),
141146
},
142147

143-
Self::At { error, .. } => Self::At {
148+
Self::At { origin, error, .. } => Self::At {
144149
error,
150+
origin,
145151
key: Some(key.into()),
146152
},
147153

148154
other => Self::At {
149155
error: Box::new(other),
156+
origin: None,
150157
key: Some(key.into()),
151158
},
152159
}
@@ -175,13 +182,15 @@ impl ConfigError {
175182
expected,
176183
key: Some(concat(key)),
177184
},
178-
Self::At { error, key } => Self::At {
185+
Self::At { error, origin, key } => Self::At {
179186
error,
187+
origin,
180188
key: Some(concat(key)),
181189
},
182190
Self::NotFound(key) => Self::NotFound(concat(Some(key))),
183191
other => Self::At {
184192
error: Box::new(other),
193+
origin: None,
185194
key: Some(concat(None)),
186195
},
187196
}
@@ -242,13 +251,21 @@ impl fmt::Display for ConfigError {
242251
Ok(())
243252
}
244253

245-
ConfigError::At { ref error, ref key } => {
254+
ConfigError::At {
255+
ref error,
256+
ref origin,
257+
ref key,
258+
} => {
246259
write!(f, "{error}")?;
247260

248261
if let Some(ref key) = *key {
249262
write!(f, " for key `{key}`")?;
250263
}
251264

265+
if let Some(ref origin) = *origin {
266+
write!(f, " in {origin}")?;
267+
}
268+
252269
Ok(())
253270
}
254271

0 commit comments

Comments
 (0)