Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Builder::try_parse() method #324

Merged
merged 3 commits into from
Jul 23, 2024
Merged

Add Builder::try_parse() method #324

merged 3 commits into from
Jul 23, 2024

Conversation

Maximkaaa
Copy link
Contributor

Current implementation of the Builder::parse() method prints out specification errors to stderr and then just ignores them. This is fine for most console applications, but in some cases better control over what is happening is needed:

  • Sometimes there is no access to stderr, in that case there is no way to find out what went wrong
  • For some applications it's more desirable to fail on startup than to run with (partially) invalid configuration.

For such cases this PR introduces a new method try_parse that does the same thing as the parse method, but returns an Err in case an error in the specification is found.

This change was suggested in and fixes #323.

@coveralls
Copy link

coveralls commented Jul 18, 2024

Pull Request Test Coverage Report for Build 10060325859

Details

  • 12 of 40 (30.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-1.0%) to 42.535%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/env_filter/src/filter.rs 5 12 41.67%
crates/env_filter/src/parser.rs 7 28 25.0%
Totals Coverage Status
Change from base Build 9504345986: -1.0%
Covered Lines: 245
Relevant Lines: 576

💛 - Coveralls

@epage
Copy link
Contributor

epage commented Jul 19, 2024

Thanks for moving this forward!

@Maximkaaa
Copy link
Contributor Author

I fixed all the comments except the last one, since I think that the current approach is better. If you insist on returning just one error string, I will edit it also.

@Maximkaaa Maximkaaa requested a review from epage July 20, 2024 14:59
@epage
Copy link
Contributor

epage commented Jul 23, 2024

Looks like the final commit needs cargo fmt run on it

Current implementation of the Builder::parse() method prints out
specification errors to stderr and then just ignores them. This is fine
for most console applications, but in some cases better control over
what is happening is needed:

* Sometimes there is no access to stderr, in that case there is no way
to find out what went wrong.

* For some applications it's more
desirable to fail on startup than to run with (partially) invalid
configuration.

For such cases this commit introduces a new method try_parse that does
the same thing as the parse method, but returns an Err in case an error
in the specification is found.
@Maximkaaa
Copy link
Contributor Author

Looks like the final commit needs cargo fmt run on it

Done.

@epage epage enabled auto-merge July 23, 2024 15:01
@epage epage merged commit 4dd976b into rust-cli:main Jul 23, 2024
16 checks passed
@epage
Copy link
Contributor

epage commented Jul 23, 2024

Thanks! This is now released.

@Maximkaaa Maximkaaa deleted the try_parse branch July 23, 2024 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a fitler parsing function returning Result instead of writing errors to stderr
3 participants