Skip to content

Commit

Permalink
fix: Support for parser errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Dec 10, 2023
1 parent 7a0508f commit f3b86a8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

#### 🚀 Updates

- Updated help text to also apply for parser errors.

## 0.12.11

#### 🚀 Updates
Expand Down
3 changes: 3 additions & 0 deletions crates/config/src/config/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ pub enum ConfigError {
#[diagnostic_source]
#[source]
error: ParserError,

#[help]
help: Option<String>,
},

// Validator
Expand Down
2 changes: 1 addition & 1 deletion crates/config/src/config/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl<T: Config> ConfigLoader<T> {
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
Expand Down
8 changes: 7 additions & 1 deletion crates/config/src/config/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,19 @@ impl Source {
}

/// Parse the source contents according to the required format.
pub fn parse<D>(&self, location: &str, cacher: &mut BoxedCacher) -> Result<D, ConfigError>
pub fn parse<D>(
&self,
location: &str,
cacher: &mut BoxedCacher,
help: Option<&str>,
) -> Result<D, ConfigError>
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 {
Expand Down

0 comments on commit f3b86a8

Please sign in to comment.