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

Command does not load dotenv files if some do not exist #175

Open
evandam opened this issue Apr 8, 2022 · 4 comments · May be fixed by #181 or #187
Open

Command does not load dotenv files if some do not exist #175

evandam opened this issue Apr 8, 2022 · 4 comments · May be fixed by #181 or #187

Comments

@evandam
Copy link

evandam commented Apr 8, 2022

Hi @joho, I noticed some unexpected behavior when using godotenv from the command line. When passing multiple .env files, if one listed first does not exist, it looks like it skips processing the rest.

For example:

$ cat .env
FOO="Using .env"

$ godotenv -f ".env,.env.doesnotexist" env | grep FOO
FOO=Using .env

$ godotenv -f ".env.doesnotexist,.env" env | grep FOO
# FOO does not get set

Any thoughts on a solution for this?

Thanks in advance!

@egasimov
Copy link

egasimov commented Jun 11, 2022

Hi @evandam,

I have looked at the godotenv project and came to the following conclusion that confirms your assumption.

When the any of the passed fileNames do not exist, it just silently stops the process of 'load env files'
and start to execute the command provided.

I believe that behaviour might lead to unexpected results and assumptions which might affect the correctness of the system that utilizes the environment variables using godotenv command
And decided to make small PR.

Current behaviour:
Silently stopping the process of 'load env files' and continuing to execute the command provided.

$ cat .env
FOO="Using .env"

$ godotenv -f ".env,.env.doesnotexist" env | grep FOO
FOO=Using .env

$ godotenv -f ".env.doesnotexist,.env" env | grep FOO
# FOO does not get set

Considered behaviour:
When the fileName do not exist, then print the message "The system cannot find the file spec" and exit.

$ cat .env
FOO="Using .env"

$ godotenv -f ".env,.env.doesnotexist" env | grep FOO
FOO=Using .env

$ godotenv -f ".env.doesnotexist,.env" env | grep FOO
open .env.doesnotexist: The system cannot find the file spec

@scalp42
Copy link

scalp42 commented Jun 11, 2022

@egasimov thanks a lot for the PR but I don't think it should error out. It'd be better if it was just skipping whatever file not existing but still load the files found. This is usually the pattern with dotenv.

@evandam
Copy link
Author

evandam commented Jun 11, 2022

Agreed with @scalp42. This way we can handle "optional" dotenv files like a .env.local that a developer may or may not have when they run in their environments.

@egasimov
Copy link

egasimov commented Jun 12, 2022

@scalp42 welcome,

Agree with you, my previous change may also introduce breaking changes for the systems that already use it somehow.

After considering your thoughts(@scalp42, @evandam ), I made another PR that simply loads all the files which do exist and prints stderr about the filenames which are missing.
I think that printing an informative message - might be helpful for people being aware of which files are not loaded by godotenv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants