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

Potentially confusing examples in documentation #42

Open
codesections opened this issue Apr 12, 2020 · 2 comments
Open

Potentially confusing examples in documentation #42

codesections opened this issue Apr 12, 2020 · 2 comments

Comments

@codesections
Copy link

Thanks very much for this crate.

The examples in the README and the documentation all show using dotenv::dotenv().ok() or dotenv::from_filename("custom.env").ok(). The .ok() causes dotenv to silently ignore errors in loading the environment file. Perhaps that should have been obvious to me, but it wasn't, especially when I first started using the crate a few months ago. Given how explicit Rust typically is with errors, this wasn't the behavior I expected. I've learned my lesson, but wondered if others might also have been confused.

I understand not wanting to have full error handling in examples, but the most common way I've seen this handled in the Rust ecosystem is to use expect. Would you be open to changing the documentation examples to something like dotenv::dotenv().expect("Could not open .env file")? If so, I'd be happy to submit a PR.

@ZoeyR
Copy link
Contributor

ZoeyR commented Apr 13, 2020

I would be more than happy to accept a PR changing this in the examples.

@Plecra
Copy link
Contributor

Plecra commented Jun 25, 2020

The dotenv function will return an error so long as it can't find a .env file. That isn't generally considered an error state for programs loading environment variables like this, since the file is just one way to pass environment variables into the function. I'd say dotenv().ok() is typically the right way to use the crate.

Definitely in support of improving the documentation to avoid this misconception, but I don't think expect is the right solution.

Edit: #57 has a reasonable solution to this

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

No branches or pull requests

3 participants