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

Running parse should not mutate the environment #9

Closed
pbrisbin opened this issue Mar 12, 2018 · 3 comments
Closed

Running parse should not mutate the environment #9

pbrisbin opened this issue Mar 12, 2018 · 3 comments

Comments

@pbrisbin
Copy link

pbrisbin commented Mar 12, 2018

Sample code:

loadConfig :: IO String
loadConfig = Env.parse id $ Env.var Env.str "STR" mempty

main :: IO ()
main = do
    print =<< loadConfig
    print =<< loadConfig

Expected outcome

% stack build && STR=str stack exec example
"str"
"str"

Actual outcome:

% stack build && STR=str stack exec example
"str"
Available environment variables:

  STR

Parsing errors:

  STR is unset

This is breaking things for me because my app loads configuration from the environment at startup, and we load a new App value for each of our test cases. So the first test case reads the environment, unsets everything, then subsequent test cases fail.

@pbrisbin
Copy link
Author

pbrisbin commented Mar 22, 2018

It looks like there is a keep modifier to prevent this, so it seems intentional. Would you mind explaining the value of having things unset by default? I'm considering setting keep all the time as a matter of course, but I wonder if I'm missing some landmine that'll bite us later, which has led to your choice in default.

@pbrisbin
Copy link
Author

Aha, I just found #6!

As for the default behavior, although it's safer to unset everything and ask the user to mark the variables they want to keep, it's unclear to me how surprising that is.

Clearly, I was indeed surprised by this :) Would you accept a PR that reversed that default, and replaced keep with something like clear or sensitive to make the unset opt-in?

pbrisbin added a commit to pbrisbin/envparse that referenced this issue Mar 28, 2018
Replaces the keep modifier with a clear modifier. The functionality is
the same, but now the env clearing is opt-in instead of opt-out.

Fixes supki#9
@supki supki closed this as completed in 19f4fbb Aug 20, 2019
@supki
Copy link
Owner

supki commented Aug 20, 2019

I've come to agree that this was the wrong default, even though it'd been moderately useful in some projects with less experienced developers at $WORK. Most people don't really expect parsing to modify their environment.

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