bkeepers / dotenv

A Ruby gem to load environment variables from `.env`.
MIT License
6.61k stars 505 forks source link

Rails < v6.1: LocalJumpError in tagged logging #480

Closed bensheldon closed 9 months ago

bensheldon commented 9 months ago

Congrats on the new release! I think I found a problem with Rails 6.0. Though I'm a little confused because I'm using dotenv and not dotenv-rails which does seem to have the correct required version number:

https://github.com/bkeepers/dotenv/blob/dd40e1c51eb63278a96724cc7150781e46cd2e94/dotenv-rails.gemspec#L13

...so feel free to close this out if it turns out the problem is that I should be using dotenv-rails instead of dotenv.

Steps to reproduce

Rails 6.0's tagged logging method requires that a block is used. This was introduced in Rails 6.1: https://github.com/rails/rails/pull/38850

When using the new 3.0 release with Rails 6.0, it produces a LocalJumpError because dotenv uses the non-block version which doesn't exist on that older version of Rails:

https://github.com/bkeepers/dotenv/blob/dd40e1c51eb63278a96724cc7150781e46cd2e94/lib/dotenv/rails.rb#L87

LocalJumpError: no block given (yield) (LocalJumpError)
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-6.0.6.1/lib/active_support/tagged_logging.rb:80:in `block in tagged'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-6.0.6.1/lib/active_support/tagged_logging.rb:28:in `tagged'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-6.0.6.1/lib/active_support/tagged_logging.rb:80:in `tagged'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/dotenv-3.0.0/lib/dotenv/rails.rb:87:in `block in <class:Rails>'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/railties-6.0.6.1/lib/rails/initializable.rb:32:in `instance_exec'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/railties-6.0.6.1/lib/rails/initializable.rb:32:in `run'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/railties-6.0.6.1/lib/rails/initializable.rb:61:in `block in run_initializers'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/3.3.0/tsort.rb:231:in `block in tsort_each'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/3.3.0/tsort.rb:353:in `block (2 levels) in each_strongly_connected_component'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/3.3.0/tsort.rb:434:in `each_strongly_connected_component_from'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/3.3.0/tsort.rb:352:in `block in each_strongly_connected_component'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/3.3.0/tsort.rb:350:in `each'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/3.3.0/tsort.rb:350:in `call'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/3.3.0/tsort.rb:350:in `each_strongly_connected_component'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/3.3.0/tsort.rb:229:in `tsort_each'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/3.3.0/tsort.rb:208:in `tsort_each'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/railties-6.0.6.1/lib/rails/initializable.rb:60:in `run_initializers'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/railties-6.0.6.1/lib/rails/application.rb:363:in `initialize!'
/Users/bensheldon/Repositories/bensheldon/good_job/demo/config/environment.rb:5:in `<main>'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.13/lib/zeitwerk/kernel.rb:34:in `require'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-6.0.6.1/lib/active_support/dependencies.rb:324:in `block in require'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-6.0.6.1/lib/active_support/dependencies.rb:291:in `load_dependency'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-6.0.6.1/lib/active_support/dependencies.rb:324:in `require'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/railties-6.0.6.1/lib/rails/application.rb:339:in `require_environment!'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/railties-6.0.6.1/lib/rails/application.rb:523:in `block in run_tasks_blocks'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `block in execute'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `each'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `execute'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `synchronize'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `invoke_with_call_chain'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/task.rb:243:in `block in invoke_prerequisites'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/task.rb:241:in `each'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/task.rb:241:in `invoke_prerequisites'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `synchronize'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `invoke_with_call_chain'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/task.rb:243:in `block in invoke_prerequisites'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/task.rb:241:in `each'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/task.rb:241:in `invoke_prerequisites'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `synchronize'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `invoke_with_call_chain'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/task.rb:188:in `invoke'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/application.rb:182:in `invoke_task'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `block (2 levels) in top_level'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `each'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `block in top_level'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/application.rb:147:in `run_with_threads'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/application.rb:132:in `top_level'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/railties-6.0.6.1/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rake-13.1.0/lib/rake/application.rb:208:in `standard_exception_handling'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/railties-6.0.6.1/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/railties-6.0.6.1/lib/rails/command.rb:48:in `invoke'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/railties-6.0.6.1/lib/rails/commands.rb:18:in `<top (required)>'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-6.0.6.1/lib/active_support/dependencies.rb:324:in `block in require'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-6.0.6.1/lib/active_support/dependencies.rb:291:in `load_dependency'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-6.0.6.1/lib/active_support/dependencies.rb:324:in `require'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/railties-6.0.6.1/lib/rails/engine/commands.rb:9:in `<top (required)>'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-6.0.6.1/lib/active_support/dependencies.rb:324:in `block in require'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-6.0.6.1/lib/active_support/dependencies.rb:291:in `load_dependency'
/Users/bensheldon/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-6.0.6.1/lib/active_support/dependencies.rb:324:in `require'
bin/rails:11:in `<top (required)>'

System configuration

dotenv version: 3.0.0

Rails version: 6.0.6.1

Ruby version: 3.3.0

bkeepers commented 9 months ago

:wave: hey @bensheldon, thanks for reporting the issue.

dotenv 3.0 dropped support for Rails 6.0, but I also updated it to automatically load Rails integration without requiring the dotenv-rails gem. I should probably update the Railtie to not try to load if the Rails version < 6.1.

bensheldon commented 9 months ago

Thank you! It seemed like user-error on my part, but figured some other folks might be in the same boat.