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 a fitler parsing function returning Result instead of writing errors to stderr #323

Open
Maximkaaa opened this issue Jul 17, 2024 · 1 comment · May be fixed by #324
Open

Add a fitler parsing function returning Result instead of writing errors to stderr #323

Maximkaaa opened this issue Jul 17, 2024 · 1 comment · May be fixed by #324

Comments

@Maximkaaa
Copy link

I suggest adding a new method env_filter::filter::try_parse(&mut self, filters: &str) -> Result<&mut Self, ParsingError>. This would imply adding a new ParsingError type and a small refactoring, but would make the library more convenient in some situations.

In my use case, I don't have access to the contents of stderr when the application is starting, and I actually don't want the application to start if the logger is configured incorrectly. Such a method would let me do this without copying the parser implementation to the application code.

If the maintainers agree that this can be added to the env_logger, I am happy to create a PR.

@epage
Copy link
Contributor

epage commented Jul 17, 2024

I think its a reasonable addition.

Maximkaaa added a commit to Maximkaaa/env_logger that referenced this issue Jul 18, 2024
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 rust-cli#323.
Maximkaaa added a commit to Maximkaaa/env_logger that referenced this issue Jul 18, 2024
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 rust-cli#323.
@Maximkaaa Maximkaaa linked a pull request Jul 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants