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

regression in handling of .env #7835

Open
2 tasks done
sakulstra opened this issue May 2, 2024 · 4 comments
Open
2 tasks done

regression in handling of .env #7835

sakulstra opened this issue May 2, 2024 · 4 comments
Labels
T-bug Type: bug

Comments

@sakulstra
Copy link
Contributor

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (cafc260 2024-05-02T00:22:11.188280000Z)

What command(s) is the bug in?

forge script/test/etc

Operating System

macOS (Apple Silicon)

Describe the bug

Users of our tooling reported a lot of weird issues lately and i think i finally found the culprit which seems to be related to some change in how .env is handled.

In most our projects we seed some empty .env with things like SENDER=
Up until recently #3847 (comment) this was the behavior in foundry: .env never overwrites global .env. It seems like in a recent nightly the behavior changed and now not only:

  • .env suddenly has precedence over user env but also
  • empty values in .env have precedence over user env

So if you e.g. define a:

# intentionally left empty
MNEMONIC_INDEX=
LEDGER_SENDER=

it will overwrite your MNEMONIC_INDEX you might have defined in global env and leads to weird issues like a value is required for '--mnemonic-indexes <INDEXES>' but none was supplied

@sakulstra sakulstra added the T-bug Type: bug label May 2, 2024
@mattsse
Copy link
Member

mattsse commented May 2, 2024

what is "global .env"?

the load .env call that's being used does not replace existing vars

@sakulstra
Copy link
Contributor Author

@mattsse sorry typo. Wanted to write global env - meaning "environment variables that were already set" (outside of .env)

@mattsse
Copy link
Member

mattsse commented May 3, 2024

hmm this is odd

Loads environment variables from the specified path.
If variables with the same names already exist in the environment, then their values will be preserved.
Where multiple declarations for the same environment variable exist in your .env file, the first one is applied.

https://docs.rs/dotenvy/latest/dotenvy/fn.from_path.html

Is there a way to reproduce this?

@sakulstra
Copy link
Contributor Author

sure, so just do:
export RPC_MAINNET=someWorkingRPC on any repo with mainnet tests.
When you now run forge run test it will work.

Then put RPC_MAINNET= in your .env and do the same. Now it will fail with [FAIL. Reason: setup failed: invalid rpc url: ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
None yet
Development

No branches or pull requests

2 participants