-
Notifications
You must be signed in to change notification settings - Fork 1
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
Expose parse errors via Dotenv::iter
.
#5
base: main
Are you sure you want to change the base?
Conversation
src/errors.rs
Outdated
@@ -1,13 +1,15 @@ | |||
use std::env; | |||
use std::error; | |||
use std::fmt; | |||
use std::fmt::Display; | |||
use std::io; | |||
|
|||
#[derive(Debug)] | |||
#[non_exhaustive] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! I did not know about non_exhaustive
until this change and it is what allowed this PR's conservative approach of not breaking existing users / requiring a major semver bump.
Refactor `dotenv::dotenv::Iter` to expose parse errors for those interested. The parse errors are structured as opaque strings to hide the parsing implementation details (currently nom and nom's errors are the internal currency). This allows a consumer that cares about propagating errors in `.env` files to use something like: ``` let env = dotenv::from_filename(".env")?; let mut iter = env.iter(); while let Some((key, value)) = iter.try_next()? { if std::env::var(key).is_err() { std::env::set_var(key, value); } } ``` Fixes arniu#4
@@ -24,7 +24,6 @@ DOUBLE_AND_SINGLE_QUOTES_INSIDE_BACKTICKS=`double "quotes" and single 'quotes' w | |||
EXPAND_NEWLINES="expand\nnew\nlines" | |||
DONT_EXPAND_UNQUOTED=dontexpand\nnewlines | |||
DONT_EXPAND_SQUOTED='dontexpand\nnewlines' | |||
DONT_EXPAND_SQUOTED='dontexpand\nnewlines' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed this duplicated line was unintentional (it was the only one in all the examples) and it got in the way of fixing tests to assert all expected values were observed. If this was intentional though, I can go back to work on handling this differently.
Refactor
dotenv::dotenv::Iter
to expose parse errors for thoseinterested. The parse errors are structured as opaque strings to hide
the parsing implementation details (currently nom and nom's errors are
the internal currency).
This allows a consumer that cares about propagating errors in
.env
files to use something like:
Fixes #4