Skip to content

Commit

Permalink
fix: Future-proof for eventual origin tracking
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
epage committed Jan 10, 2025
1 parent da066d2 commit 7496699
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ pub enum ConfigError {
/// Error being extended with a path
error: Box<ConfigError>,

/// The URI that references the source that the value came from.
/// Example: `/path/to/config.json` or `Environment` or `etcd://localhost`
// TODO: Why is this called Origin but FileParse has a uri field?
origin: Option<String>,

/// The key in the configuration hash of this value (if available where the
/// error is generated).
key: Option<String>,
Expand Down Expand Up @@ -140,13 +145,15 @@ impl ConfigError {
key: Some(key.into()),
},

Self::At { error, .. } => Self::At {
Self::At { origin, error, .. } => Self::At {
error,
origin,
key: Some(key.into()),
},

other => Self::At {
error: Box::new(other),
origin: None,
key: Some(key.into()),
},
}
Expand Down Expand Up @@ -175,13 +182,15 @@ impl ConfigError {
expected,
key: Some(concat(key)),
},
Self::At { error, key } => Self::At {
Self::At { error, origin, key } => Self::At {
error,
origin,
key: Some(concat(key)),
},
Self::NotFound(key) => Self::NotFound(concat(Some(key))),
other => Self::At {
error: Box::new(other),
origin: None,
key: Some(concat(None)),
},
}
Expand Down Expand Up @@ -242,13 +251,21 @@ impl fmt::Display for ConfigError {
Ok(())
}

ConfigError::At { ref error, ref key } => {
ConfigError::At {
ref error,
ref origin,
ref key,
} => {
write!(f, "{error}")?;

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

if let Some(ref origin) = *origin {
write!(f, " in {origin}")?;
}

Ok(())
}

Expand Down

0 comments on commit 7496699

Please sign in to comment.