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

dotenv-path unexpectedly loads .env from parent directory #2257

Open
yossarian21 opened this issue Jul 17, 2024 · 1 comment
Open

dotenv-path unexpectedly loads .env from parent directory #2257

yossarian21 opened this issue Jul 17, 2024 · 1 comment

Comments

@yossarian21
Copy link

yossarian21 commented Jul 17, 2024

I'm using just@1.31.0 on Mac.

The documentation states:

If dotenv-path is set, just will look for a file at the given path, which may be absolute, or relative to the working directory.
dotenv-filename and dotenv-path and similar, but dotenv-path is only checked relative to the working directory, whereas dotenv-filename is checked relative to the working directory and each of its ancestors.

I tried configuring my justfile as follows:

set dotenv-path := "."

_default:
    @just --list

There is no .env file in the current directory, but in the parent directory, I created a bogus .env file, e.g.

daofinasdfoiasdn

In the current directory with my justfile, I get this error:

just
error: Failed to load environment file: Error parsing line: 'daofinasdfoiasdn', error at line index: 16

Expectation: dotenv-path should only load a .env file from the specified path.

@casey
Copy link
Owner

casey commented Jul 18, 2024

This is an annoying consequence of the way that the various dotenv settings work.

Setting any dotenv- setting turns on dotenv loading, which uses both dotenv-filename and dotenv-path. dotenv-filename defaults to .env, so even if you set dotenv-path, just will still also try to use dotenv-filename to load an environment file.

So, even though you set dotenv-path := ".", dotenv-filename still has the default value of .env, and the environment file in the parent directory is loaded.

This is definitely not ideal behavior, and if I could go back in time, I would definitely make dotenv-filenmae and dotenv-path not have default values, which would enable you to get the behavior you want.

Part of the reason that these settings are weird and continue to be weird is that someone could be relying on the existing behavior, and so changing them to be less weird might break someone's setup.

Probably the best way to fix this would be to introduce a new setting (sigh) which if used would provide better behavior.

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

2 participants