allow warning when a env var was not overwritten#531
Conversation
bkeepers
left a comment
There was a problem hiding this comment.
Thanks for the pull request! I get the frustration when you realize that a local variable was set and couldn't figure out why something was not working.
Would it make sense to warn by default? I wonder if there's a clean way to say which variables were set from .env and which were already set.
lib/dotenv.rb
Outdated
| overwrite ? new_value : old_value | ||
| case overwrite | ||
| when :warn | ||
| warn "Warning: Not overwriting ENV['#{key}'] with '#{new_value}' (is '#{old_value}')" |
There was a problem hiding this comment.
Can this use the logger instead of warn? I am also hesitant about printing the values because they could contain secrets.
There was a problem hiding this comment.
yeah good point, keys should be enough
There was a problem hiding this comment.
... how do you suggest using the logger, in non-rails there is no logger right ?
removed the values and changed to .inspect just in case there is some escaping to be worried about
|
re "warn by default" afaik no other dotenv library does that, so I'd rather not make that the default |
|
also added gem name to warning so people have a chance of knowing what is going on |
* main: Fix lint error Remove sponsor feat: remove to_sentence usage Add test for command to variable to command Handle parentheses in variables in commands
* main: Bump actions/checkout from 4 to 6 fix a few small issues
too many times I'm trying to debug someones issues and it's "oh you already set xyz api key in your env" 🤦
so
Dotenv.load files, overwrite: :warnwould tell them that it's already set.... might also get annoying after a while 🤷 but wanted to raise an issue since this seems be a common gotcha
might want to make it set+warn instead, to keep the
override is truthybehavior, lmkFYI similar but hacky way of doing it: