ruby / vscode-rdbg

VSCode Ruby rdbg Debugger
MIT License
176 stars 50 forks source link

Can no longer properly use rbenv ruby version #112

Open johnvictorfs opened 1 year ago

johnvictorfs commented 1 year ago

I have been using the following config for this extension (and some other similar ones) for a couple of months, with a workaround to load rbenv so it doesn't use my system ruby version/gems:

{
  "name": "Debug spec",
  "type": "rdbg",
  "request": "launch",
  "useBundler": false,
  "script": "${relativeFile}",
  "rdbgPath": "PATH=$HOME/.rbenv/shims:${PATH} ${workspaceFolder}/bin/rdbg",
  "command": "${workspaceFolder}/bin/rspec",
  "cwd":"${workspaceFolder}"
},

Using "rdbgPath": "PATH=$HOME/.rbenv/shims:${PATH} ${workspaceFolder}/bin/rdbg", no longer works, fails with the message below, without any useful logs in the 'Output' tab:

image

It now requires me to use "rdbgPath": "${workspaceFolder}/bin/rdbg",, which doesn't load rbenv, tries to use my system ruby and breaks

[Start session]
{"_debugServiceProxy":{},"_id":"45c6a9ad-0a35-465c-adc8-5784c65c500c","_type":"rdbg","_name":"Debug spec","_workspaceFolder":{"uri":{"$mid":1,"fsPath":"/home/john/projects/yuri","external":"file:///home/john/projects/yuri","path":"/home/john/projects/yuri","scheme":"file"},"name":"yuri","index":0},"_configuration":{"name":"Debug spec","type":"rdbg","request":"launch","useBundler":true,"script":"/home/john/projects/yuri/spec/some_censored_spec_file.rb","rdbgPath":"$HOME/.rbenv/shims/rdbg","command":"/home/john/projects/yuri/bin/rspec","cwd":"/home/john/projects/yuri","bundlePath":"/home/john/projects/yuri/bin/bundle","useTerminal":true,"env":{"PATH":"<MY_PATH_HERE>"},"__configurationTarget":6}}
[Error on session]
Error: connection closed
e: {}
/usr/lib/ruby/3.0.0/bundler/definition.rb:432:in `validate_ruby!': Your Ruby version is 3.0.4, but your Gemfile specified 3.1.2 (Bundler::RubyVersionMismatch)
    from /usr/lib/ruby/3.0.0/bundler/definition.rb:407:in `validate_runtime!'
    from /usr/lib/ruby/3.0.0/bundler.rb:155:in `setup'
    from /usr/lib/ruby/3.0.0/bundler/setup.rb:20:in `block in <top (required)>'
    from /usr/lib/ruby/3.0.0/bundler/ui/shell.rb:136:in `with_level'
    from /usr/lib/ruby/3.0.0/bundler/ui/shell.rb:88:in `silence'
    from /usr/lib/ruby/3.0.0/bundler/setup.rb:20:in `<top (required)>'
    from <internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
    from <internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
    from /home/john/projects/yuri/bin/rdbg:25:in `<main>'

Error: exit code is 1
Make sure to install rdbg command (`gem install debug`).
If you are using bundler, write `gem 'debug'` in your Gemfile.

I have also tried the following config, also with no success (same error):

{
      "name": "Debug spec",
      "type": "rdbg",
      "request": "launch",
      "useBundler": false,
      "script": "${relativeFile}",
      "rdbgPath": "${workspaceFolder}/bin/rdbg",
      "command": "${workspaceFolder}/bin/rspec",
      "cwd":"${workspaceFolder}",
      "env": {
        "PATH": "$HOME/.rbenv/shims:${env:PATH}"
      },
    },

Using "useBundler": true with any of the config variations above also fails, with same error messages, even when specifying a bundlePath

Any way I can fix this? I could probably setup some setting in my shell to pre-load rbenv but I would like a solution that stays self-contained in the VsCode config, so I don't need to have everyone in my company manually fix this issue in their systems

ono-max commented 1 year ago

Could you show us the sample program to reproduce this problem?

johnvictorfs commented 1 year ago

Sure thing!

Here's a reproduction repo https://github.com/johnvictorfs/vscode-rbdg-issue

In the repo I have setup two different vscode debugging configs, one for the latest version of the extension (v0.1.0) and another one for the old one (v0.0.11), when it used to work fine, with the only changes being the required ones, noted in the comments


Steps to reproduce


Using vscode-rdbg at v0.0.11 works fine with the following settings as screenshot below shows:

{
  "name": "Debug spec (v0.0.11)",
  "type": "rdbg",
  "request": "launch",
  "useBundler": false,
  "script": "${relativeFile}",
  "rdbgPath": "PATH=$HOME/.rbenv/shims:$PATH bin/rdbg",
  "command": "rspec",
  "cwd":"${workspaceFolder}",
  "env": {
    "PATH": "${env:PATH}"
  }
}

image


Now, if I update to latest version of the extension, my old settings break because of PATH=$HOME/.rbenv/shims:$PATH, which I needed to load rbenv properly, so it stops working with the almost same setting below (except forced changes shown by the comments)

{
  "name": "Debug spec (v0.1.0)",
  "type": "rdbg",
  "request": "launch",
  "useBundler": false,
  "script": "${relativeFile}",
  "rdbgPath": "bin/rdbg", // necessary on v0.1.0, but doesn't work
  "command": "rspec",
  "cwd":"${workspaceFolder}",
  "useTerminal": true, // required to see proper error traceback
  "env": {
    "PATH": "${env:PATH}"
  }
}

image


Below is what happens if I try to run the old launch.json config, with the latest extension version:

image

ono-max commented 1 year ago

@johnvictorfs

Thank you! To clarify the problem, let me ask one question:

Does it work with the following launch.json?

{
  "name": "Debug spec (v0.1.0)",
  "type": "rdbg",
  "request": "launch",
  "useBundler": false,
  "script": "${relativeFile}",
  "rdbgPath": "bin/rdbg", // necessary on v0.1.0, but doesn't work
  "command": "rspec",
  "cwd":"${workspaceFolder}"
}
johnvictorfs commented 1 year ago

Hello @ono-max it does not work

I get the following pop-up error with no logs in the Debug console:

image

And this is all the Output tab shows:

"Running: bin/rdbg --command --open --stop-at-load -- rspec spec/models/job_spec.rb"
[Start session]
{"d":{},"f":"35074f39-b8b3-435f-9e52-22bdf71948b1","g":"rdbg","h":"Debug spec (v0.1.0)","i":{"uri":{"$mid":1,"fsPath":"/home/john/projects/***","external":"file:///home/john/projects/***","path":"/home/john/projects/***","scheme":"file"},"name":"***","index":0},"j":{"name":"Debug spec (v0.1.0)","type":"rdbg","request":"launch","useBundler":false,"script":"spec/models/job_spec.rb","rdbgPath":"bin/rdbg","command":"rspec","cwd":"/home/john/projects/***","__configurationTarget":6}}

(Some folder names censored)

If I change the settings to the following:

{
  "name": "Debug spec (v0.1.0)",
  "type": "rdbg",
  "request": "launch",
  "useBundler": false,
  "script": "${relativeFile}",
  "rdbgPath": "bin/rdbg", // necessary on v0.1.0, but doesn't work
  "command": "rspec",
  "useTerminal": true, // Added this setting
  "cwd":"${workspaceFolder}"
},

I get some Output for the error:

/usr/lib/ruby/3.0.0/bundler/definition.rb:431:in `validate_ruby!': Your Ruby version is 3.0.5, but your Gemfile specified 3.1.2 (Bundler::RubyVersionMismatch)
    from /usr/lib/ruby/3.0.0/bundler/definition.rb:406:in `validate_runtime!'
    from /usr/lib/ruby/3.0.0/bundler.rb:164:in `setup'
    from /usr/lib/ruby/3.0.0/bundler/setup.rb:20:in `block in <top (required)>'
    from /usr/lib/ruby/3.0.0/bundler/ui/shell.rb:159:in `with_level'
    from /usr/lib/ruby/3.0.0/bundler/ui/shell.rb:111:in `silence'
    from /usr/lib/ruby/3.0.0/bundler/setup.rb:20:in `<top (required)>'
    from <internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
    from <internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
    from bin/rdbg:25:in `<main>'

Error: exit code is 1
Make sure to install rdbg command (`gem install debug`).
If you are using bundler, write `gem 'debug'` in your Gemfile.

Because I have multiple ruby versions installed, I use Rbenv to manage them between projects, and the extension just tries to use the system one, and my workaround I used to load Rbenv before stopped working

I do think, however, that this open PR would fix my issue https://github.com/ruby/vscode-rdbg/pull/113

ko1 commented 1 year ago

which shell do you use and how to setup the rbenv on your login shell?

johnvictorfs commented 1 year ago

Zsh, I setup my rbenv with this:

if [ -x "$(command -v rbenv)" ]; then
    eval "$(rbenv init -)"
fi
ono-max commented 1 year ago

@johnvictorfs

Sorry for waiting for you. Could you try v0.2.0 when having time?