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

Skip over non-envvar lines #285

Closed
sloria opened this issue Feb 20, 2017 · 4 comments · Fixed by #291
Closed

Skip over non-envvar lines #285

sloria opened this issue Feb 20, 2017 · 4 comments · Fixed by #291
Labels

Comments

@sloria
Copy link
Contributor

sloria commented Feb 20, 2017

.env files may contain lines that don't set environment variables. For example, I use autoenv in order to automatically activate the current project's Python virtual environment. I also set per-project aliases in .env.

dotenv raises an error when it encounters lines that don't set envvars:

/usr/local/lib/ruby/gems/2.4.0/gems/dotenv-2.2.0/lib/dotenv/parser.rb:63:in `parse_line': Line "source activate osf" doesn't match format (Dotenv::FormatError)
        from /usr/local/lib/ruby/gems/2.4.0/gems/dotenv-2.2.0/lib/dotenv/parser.rb:47:in `block in call'
        from /usr/local/lib/ruby/gems/2.4.0/gems/dotenv-2.2.0/lib/dotenv/parser.rb:46:in `each'
        from /usr/local/lib/ruby/gems/2.4.0/gems/dotenv-2.2.0/lib/dotenv/parser.rb:46:in `call'
        from /usr/local/lib/ruby/gems/2.4.0/gems/dotenv-2.2.0/lib/dotenv/parser.rb:36:in `call'
        from /usr/local/lib/ruby/gems/2.4.0/gems/dotenv-2.2.0/lib/dotenv/environment.rb:13:in `load'
        from /usr/local/lib/ruby/gems/2.4.0/gems/dotenv-2.2.0/lib/dotenv/environment.rb:9:in `initialize'
        from /usr/local/lib/ruby/gems/2.4.0/gems/dotenv-2.2.0/lib/dotenv.rb:15:in `new'
        from /usr/local/lib/ruby/gems/2.4.0/gems/dotenv-2.2.0/lib/dotenv.rb:15:in `block (2 levels) in load'
        from /usr/local/lib/ruby/gems/2.4.0/gems/dotenv-2.2.0/lib/dotenv.rb:59:in `ignoring_nonexistent_files'
        from /usr/local/lib/ruby/gems/2.4.0/gems/dotenv-2.2.0/lib/dotenv.rb:14:in `block in load'
        from /usr/local/lib/ruby/gems/2.4.0/gems/dotenv-2.2.0/lib/dotenv.rb:46:in `block in with'
        from /usr/local/lib/ruby/gems/2.4.0/gems/dotenv-2.2.0/lib/dotenv.rb:45:in `each'
        from /usr/local/lib/ruby/gems/2.4.0/gems/dotenv-2.2.0/lib/dotenv.rb:45:in `reduce'
        from /usr/local/lib/ruby/gems/2.4.0/gems/dotenv-2.2.0/lib/dotenv.rb:45:in `with'
        from /usr/local/lib/ruby/gems/2.4.0/gems/dotenv-2.2.0/lib/dotenv.rb:13:in `load'
        from /usr/local/lib/ruby/gems/2.4.0/gems/docker-sync-0.2.0/lib/docker-sync/sync_manager.rb:19:in `initialize'
        from /usr/local/lib/ruby/gems/2.4.0/gems/docker-sync-0.2.0/tasks/sync/sync.thor:30:in `new'
        from /usr/local/lib/ruby/gems/2.4.0/gems/docker-sync-0.2.0/tasks/sync/sync.thor:30:in `start'
        from /usr/local/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor/command.rb:27:in `run'
        from /usr/local/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command'
        from /usr/local/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor.rb:369:in `dispatch'
        from /usr/local/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor/base.rb:444:in `start'
        from /usr/local/lib/ruby/gems/2.4.0/gems/docker-sync-0.2.0/bin/docker-sync:14:in `<top (required)>'
        from /usr/local/bin/docker-sync:22:in `load'
        from /usr/local/bin/docker-sync:22:in `<main>'

Would the maintainer(s) be open to skipping these lines rather than raising an error?

@sloria
Copy link
Contributor Author

sloria commented Feb 20, 2017

For what it's worth, both Foreman (https:/ddollar/foreman/blob/5f5502efed74c68f5cf381d38b2ad497676837ec/lib/foreman/env.rb#L8-L18) and honcho (https:/nickstenning/honcho/blob/6bad0da2806231ac8f3a07d76847a566b96745e6/honcho/environ.py#L73-L99) implement the suggested behavior (skipping lines that don't set envvars).

@sloria
Copy link
Contributor Author

sloria commented Mar 16, 2017

Is this something the maintainers would be willing to change? If so, I could work on a PR.

@bkeepers
Copy link
Owner

Hey @sloria, thanks for the suggestion. I'm not opposed. My only concern is that it might lead to unexpected behavior for people that don't realize they have the format wrong, but I think I'm ok with that.

Feel free to open a PR!

@stale
Copy link

stale bot commented May 15, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot closed this as completed May 22, 2017
cbjoseph pushed a commit to cbjoseph/dotenv that referenced this issue Apr 16, 2018
This makes dotenv play better with .env files that
do more than just set variables, e.g. defining aliases
and functions

closes bkeepers#285
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants