Closed xiaoas closed 1 year ago
The reason for the .ok()
is to ignore the error.
The .env
file this loads might not be available on the deployed version of a user's app. The environment variables would usually be set elsewhere. By using this pattern no error is thrown if the file isn't found.
As some users may require a .env
file, they have the option of using its result type.
You are right: there needs to be better documentation around this issue. It certainly doesn't feel very "rusty" to just .ok()
an error like that.
@xiaoas, thanks for reporting. It's been brought up a few times already that .ok()
is not ideal.
I've replaced some .ok()
s in the docs with .unwrap()
but there are still a few instances left, including the README example.
Feel free to open a PR.
The example in README use
dotenvy::dotenv
feels miss-leading:calling
.ok
on dotenv(), aResult
, turns it into aOption
. This is not what most people might expect imo. Changing to some error handling might better serve the intention: