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

rdbg doesn't respect the bundler/setup loaded by bundler #715

Closed
st0012 opened this issue Jul 13, 2022 · 0 comments · Fixed by #716
Closed

rdbg doesn't respect the bundler/setup loaded by bundler #715

st0012 opened this issue Jul 13, 2022 · 0 comments · Fixed by #716

Comments

@st0012
Copy link
Member

st0012 commented Jul 13, 2022

Your environment

  • ruby -v: 3.1
  • rdbg -v: 1.6.1

Describe the bug

When running bundle exec, bundler will inject something like -r path_to_bundler/setup into the RUBYOPT environment variable. And that's how it makes sure every gem loaded afterward is at the version specified in the Gemfile.lock.

But currently, the rdbg executable aren't passing this info correctly.

debug/exe/rdbg

Lines 16 to 21 in 390b764

env = ::DEBUGGER__::Config.config_to_env_hash(config)
rubyopt = env['RUBYOPT']
env['RUBY_DEBUG_ADDED_RUBYOPT'] = added = "-r #{libpath}/#{start_mode}"
env['RUBYOPT'] = "#{added} #{rubyopt}"
exec(env, cmd, *ARGV)

This code has 2 problems:

  1. rubyopt = env['RUBYOPT'] should be rubyopt = ENV['RUBYOPT'] because env is a hash produced with the debugger configurations instead of the current environment. So currently the env['RUBYOPT'] is always nil.
  2. "#{added} #{rubyopt}" should be #{rubyopt} "#{added} instead to honor the requiring order.
    • -rbundler/setup -rdebug/start instead of -rdebug/start -rbundler/setup because the later will cause the debugger not to load the dependency specified in Gemfile.

To Reproduce

This problem doesn't always cause real issues though. Errors only happen when all these conditions are fulfilled:

  1. There's a library used by both the debugger and the user's program, e.g. timeout (used by reline, which is used by the debugger)
  2. The system has at least 2 versions of the gem (e.g. 0.2.0 and 0.3.0)
  3. The user program uses the older version (e.g. 0.2.0)

Then rdbg -c -- <user program> will trigger this error:

You have already activated timeout 0.3.0, but your Gemfile requires timeout 0.2.0. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)

The real program though, is that appending bundle exec before rdbg won't fix the problem as it should due to the described reason.

Expected behavior

bundle exec rdbg # ... should avoid the Gem::LoadError.

st0012 added a commit to st0012/debug that referenced this issue Jul 13, 2022
st0012 added a commit to st0012/debug that referenced this issue Jul 13, 2022
@ko1 ko1 closed this as completed in #716 Jul 14, 2022
ko1 pushed a commit that referenced this issue Jul 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant