diff --git a/CHANGELOG.md b/CHANGELOG.md index 60e0d422..8293fee2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +#### 🚀 Updates + +- Updated help text to also apply for parser errors. + ## 0.12.11 #### 🚀 Updates diff --git a/crates/config/src/config/errors.rs b/crates/config/src/config/errors.rs index 3553691c..46c03276 100644 --- a/crates/config/src/config/errors.rs +++ b/crates/config/src/config/errors.rs @@ -84,6 +84,9 @@ pub enum ConfigError { #[diagnostic_source] #[source] error: ParserError, + + #[help] + help: Option, }, // Validator diff --git a/crates/config/src/config/loader.rs b/crates/config/src/config/loader.rs index ab87797f..fce34713 100644 --- a/crates/config/src/config/loader.rs +++ b/crates/config/src/config/loader.rs @@ -253,7 +253,7 @@ impl ConfigLoader { let partial: T::Partial = { let mut cacher = self.cacher.lock().unwrap(); - source.parse(location, &mut cacher)? + source.parse(location, &mut cacher, self.help.as_deref())? }; // Validate before continuing so we ensure the values are correct diff --git a/crates/config/src/config/source.rs b/crates/config/src/config/source.rs index 56f9c62d..16745ea2 100644 --- a/crates/config/src/config/source.rs +++ b/crates/config/src/config/source.rs @@ -98,13 +98,19 @@ impl Source { } /// Parse the source contents according to the required format. - pub fn parse(&self, location: &str, cacher: &mut BoxedCacher) -> Result + pub fn parse( + &self, + location: &str, + cacher: &mut BoxedCacher, + help: Option<&str>, + ) -> Result where D: DeserializeOwned, { let handle_error = |error: crate::config::ParserError| ConfigError::Parser { config: location.to_owned(), error, + help: help.map(|h| h.to_owned()), }; match self {