-
Notifications
You must be signed in to change notification settings - Fork 48
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
fix(docs): Handle errors, rather than using unwrap
, in examples
#52
fix(docs): Handle errors, rather than using unwrap
, in examples
#52
Conversation
?
, rather than unwrap
, in examples
|
||
fn main() { | ||
// load environment variables from .env file | ||
dotenv().expect(".env file not found"); |
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.
This line notably produced misleading error messages, claiming the file was not found even in cases where it actually contained invalid variable declarations.
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.
Good point
7365034
to
fd2a344
Compare
?
, rather than unwrap
, in examplesunwrap
, in examples
fd2a344
to
fd3e1f8
Compare
unwrap
, in examplesunwrap
, in examples
For most of these, I prefer the original. See this comparison: Original dotenvy::from_filename("custom.env").unwrap(); Suggested fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenvy::from_filename("custom.env")?;
Ok(())
} The original is more legible for illustrating the usage of I can see |
@allan2 You're missing here that rustdoc renders this as: dotenvy::from_filename("custom.env")?; The entire code block is being run as a test. Lines prefixed with This is common practice, as well as best practice in Rust projects. I would recommend you run
This isn't at all related to lengthiness, but about proliferating proper error handling. I am very sure the examples shown in the |
My apologies, I did miss that. This PR looks good to me! |
This PR
Fixes #49
Notes
A note regarding the
from_path*
example changesI simplified these examples, as they did not plainly show off usage and were somewhat nonsensical:
.as_path()
for a method acceptingAsRef<Path>
, whichPathBuf
implements.from_filename*
andfrom_path*
(which is in fact the recursive lookup in parent directories). I'll open a separate issue about that to keep the PR clean.A note regarding
dotenv_override
example changesuse
by fully qualified name to keep consistent with the otherdotenv*
examples..ok()
for consistency with thedotenvy::dotenv
example.