vscode-ruby version: 0.15.0Make sure you have ruby, ruby-debug-ide and ruby-debug-basex19 installed before submitting your issue -- thank you !
I have ruby-debug-ide installed but I cannot install the ruby-debug-base gem. It says it cannot find it in a repository. I think this instruction might be outdated since the wiki says to install the "debase" gem if we have Ruby 2.0 or higher.
Able to launch debugging.
Debugging doesn't launch. VS Code output console says:
Debugger terminal error: Process failed: spawn rdebug-ide ENOENT
I followed the installation instructions including installing the dependencies. I installed the VS Code extension "ruby" and then I saw these instructions for dependencies:
If you are using Ruby v2.x
gem install ruby-debug-ide -v 0.4.32 or higher versions
gem install debase -v 0.2.1 or higher versions
So I performed these installs and made sure they were in my gems:
$ gem list | grep "ide"
ruby-debug-ide (0.6.0)
$ gem list | grep "debase"
debase (0.2.2.beta10, 0.2.1)
debase-ruby_core_source (0.9.10)
I then followed the instructions to create the "launch.json" file automatically by going to the debug area of VS Code and choosing Ruby. My launch.json file looks like this right now:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug Local File",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/main.rb"
},
{
"name": "Listen for rdebug-ide",
"type": "Ruby",
"request": "attach",
"cwd": "${workspaceRoot}",
"remoteHost": "127.0.0.1",
"remotePort": "1234",
"remoteWorkspaceRoot": "${workspaceRoot}"
},
{
"name": "Rails server",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rails",
"args": [
"server"
]
},
{
"name": "RSpec - all",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rspec",
"args": [
"-I",
"${workspaceRoot}"
]
},
{
"name": "RSpec - active spec file only",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rspec",
"args": [
"-I",
"${workspaceRoot}",
"${file}"
]
},
{
"name": "Cucumber",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/cucumber"
}
]
}
However, when I select "Rails server" as a debug option and click the green arrow, it starts and closes immediately and I get the following message in the output console:
Debugger terminal error: Process failed: spawn rdebug-ide ENOENT
In the wiki, I noticed these instructions:
Using rvm
The default rvm will be used to run the debugger, which can lead to unexpected results if your default differs from the ruby version configured for your repo. The workaround is to change rvm's default ruby version to match the repo's expected version. In a terminal, type rvm use <ruby-version> --default to get things working. Once this is done, specifying the bundler & rdebug-ide paths is no longer required, and things load properly.
Since I use RVM, I used the rvm use 2.4.2 --default command so that my terminal would always have a Ruby selected.
Unfortunately, this did not fix the issue with VS Code debugging.
This is the RVM-related section of my .bashrc file that I had to set to get my terminal to be ready for Ruby commands when it launches:
# Fixes the "rvm is not a function"
source $HOME/.rvm/scripts/rvm
# Add RVM to PATH for scripting. Make sure this is the last PATH variable chang.
export PATH="$PATH:$HOME/.rvm/bin"
I noticed that the error message mentions an "rdebug-ide" gem so I checked my terminal to see if it could at least find this gem, I'm wondering if it could be PATH issues:
$ which rdebug-ide
/home/mwelke/.rvm/gems/ruby-2.4.2/bin/rdebug-ide
I notice the debug environment "Rails server" is attempting to run a binary in "bin" directory so I also checked to ensure I have that binary there:
βββ bin
βΒ Β βββ bundle
βΒ Β βββ bundler
βΒ Β βββ byebug
βΒ Β βββ listen
βΒ Β βββ nokogiri
βΒ Β βββ puma
βΒ Β βββ pumactl
βΒ Β βββ rackup
βΒ Β βββ rails
βΒ Β βββ rake
βΒ Β βββ sass
βΒ Β βββ sass-convert
βΒ Β βββ scss
βΒ Β βββ setup
βΒ Β βββ spring
βΒ Β βββ sprockets
βΒ Β βββ thor
βΒ Β βββ tilt
βΒ Β βββ update
βΒ Β βββ yarn
And it can... so I'm still pretty baffled right now. I suspect it has something to do with PATH, my setup, etc. Was wondering if anyone could help?
EDIT:
In order to discover more about what might be causing the issue, I tried to set up a debugging session using the "Listen for rdebug-ide" debugging environment. I created a script and called "rdebug-ide" from the terminal to look at a test script I made. I then started debugging this way from VS Code and it was able to start. It seemed to work fine.
UPDATE:
Found workaround with this comment. Looks like my ENV isn't getting passed to VS Code. Launching VS Code from the command line let's me debug:
WARN: Unresolved specs during Gem::Specification.reset:
rake (>= 0.8.1)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
Looks like your app's ./bin/rails is a stub that was generated by Bundler.
In Rails 5, your app's bin/ directory contains executables that are versioned
like any other source code, rather than stubs that are generated on demand.
Here's how to upgrade:
bundle config --delete bin # Turn off Bundler's stub generator
rails app:update:bin # Use the new Rails 5 executables
git add bin # Add bin/ to source control
=> Booting Puma
=> Rails 5.1.4 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.10.0 (ruby 2.4.2-p198), codename: Russell's Teapot
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
I tested with a breakpoint in a controller I made it was hit no problem.
So then the only problem at this point is that my ENV isn't working in VS Code. Any idea what could cause this?
+1 I ran into this same problem today. I was able to rectify the problem by adding a couple environment variables to my launch.json script; for example, adding the MY_RUBY_HOME environment variable was required to get things working.
@aryeh-looker I've added MY_RUBY_HOME to the "env" key in my launch.json, but it's still not working. Do you mind posting exactly what you did?
EDIT: Ok, I didn't think this would do anything but I added my PATH as an environment variable and it works now.
"env": {
"PATH": "/home/taylor/.rvm/gems/ruby-2.4.1/bin:/home/taylor/.rvm/gems/ruby-2.4.1@global/bin:/home/taylor/.rvm/rubies/ruby-2.4.1/bin:/home/taylor/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
}
Based on this comment, https://github.com/rubyide/vscode-ruby/issues/62#issuecomment-301198259 from hickey, this is my actual configuration to debug my Rails application:
{
"name": "Rails server",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rails",
"args": [
"server"
],
"showDebuggerOutput": true,
"env": {
"PATH": "/home/victor/.rvm/gems/ruby-2.3.1@my_app/bin:/home/victor/.rvm/gems/ruby-2.3.1@global/bin:/home/victor/.rvm/bin:/home/victor/.rvm/gems/ruby-2.3.1/bin:/home/victor/.rvm/rubies/ruby-2.3.1/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
"rvm_prefix": "/home/victor",
"rvm_path": "/home/victor/.rvm",
"rvm_bin_path": "/home/victor/.rvm/bin",
"GEM_HOME": "/home/victor/.rvm/gems/ruby-2.3.1@my_app",
"GEM_PATH": "/home/victor/.rvm/gems/ruby-2.3.1@my_app:/home/victor/.rvm/gems/ruby-2.3.1@global",
"MY_RUBY_HOME": "/home/victor/.rvm/rubies/ruby-2.3.1",
"IRBRC": "/home/victor/.rvm/rubies/ruby-2.3.1/.irbrc",
"RUBY_VERSION": "ruby-2.3.1"
}
},
The trick is trying to replicate the same environment as if you were doing a
rvm use 2.3.1@my_app
from your project folder into the terminal, to prevent conflicts with another ruby version or particular gem.
You can get all information relative to gem paths executing gem env or bundle env after selecting the gemset with rvm (rvm use 2.3.1@my_app), to get the rvm paths execute which rvm.
If you want to do a new setup for another project in your workspace with another gemset or ruby version you will need to adjust the ENV values with the particular project paths, etc...
It's a bit complicated but it works.
Hope this helps.
Closing for issue cleanup. Apologies if this is still an issue. We are working to improve the core extension experience.
Here is a quick bash printf command to give you the required env details to place into launch.json
printf "\n\"env\": {\n \"PATH\": \"$PATH\",\n \"GEM_HOME\": \"$GEM_HOME\",\n \"GEM_PATH\": \"$GEM_PATH\",\n \"RUBY_VERSION\": \"$RUBY_VERSION\"\n}\n\n"
I have a similar problem, but I am using rbenv instead of rvm, so I don't have any of those environment variables. My debugging setup also works fine when launching from the command line as opposed to my taskbar. Am I out of luck and need to switch to rvm or is there a solution that would allow me to use rbenv without having to launch vscode from the command line?
EDIT: I don't know what was different this time but I added my PATH to my launch.json file and all of a sudden it works now. I was pretty sure I tried that and it didn't work but I must have made a mistake I didn't notice earlier.
Had the exact problem! Thanks @timkrins π
This should be resolved somehow - is there a way of passing all ENVs to code or the plugin itself?
@leggettc18 can you share your launch.json config file for reference for people who is working with rbenv, please?
Just in case anyone else stumbles upon this (since I just spent about 30 min debugging), make sure that your env is specified inside the configuration object (not outside).
e.g.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug Local File",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/main.rb",
"env": {
"PATH": "/Users/et/.gem/ruby/2.5.3/bin:/Users/et/.rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/bin:/Users/et/.rubies/ruby-2.5.3/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/et/.rvm/bin:/Users/et/.rvm/bin",
"GEM_HOME": "/Users/et/.gem/ruby/2.5.3",
"GEM_PATH": "/Users/et/.gem/ruby/2.5.3:/Users/et/.rubies/ruby-2.5.3/lib/ruby/gems/2.5.0",
"RUBY_VERSION": "2.5.3"
}
}
]
}
very helpful thanks!
As an alternative to specifying your env inside the launch.json file, try starting VSCode from the terminal instead of from e.g. the Dock on macOS. This will ensure that any processes spawned by VSCode will inherit the environment variables defined in the terminal session.
Credit goes to the following comment for this workaround.
Try to make a imperfect conclusion about
Debugger terminal error: Process failed: spawn rdebug-ide ENOENT
First
Please follow https://github.com/rubyide/vscode-ruby#install-ruby-dependencies and make sure you can run ruby-debug-ide directly on your machine
Second
Third
if it do, add the env configuration
It did help me, thank u
Here is a quick bash printf command to give you the required env details to place into
launch.jsonprintf "\n\"env\": {\n \"PATH\": \"$PATH\",\n \"GEM_HOME\": \"$GEM_HOME\",\n \"GEM_PATH\": \"$GEM_PATH\",\n \"RUBY_VERSION\": \"$RUBY_VERSION\"\n}\n\n"
I still see this error message even if I set the proper environment for the launch configuration. I also tried pathToRDebugIDE but it doesnβt help. Any ideas? Shall I create a new issue for this?
I still see this error message even if I set the proper environment for the launch configuration. I also tried
pathToRDebugIDEbut it doesnβt help. Any ideas? Shall I create a new issue for this?
I fixed it by putting env PATH into launch.js, so mine is like this and is working fine:
"configurations": [
{
"name": "Debug Local File",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${file}",
"env": {
"PATH": "/home/ales/.gem/ruby/2.6.0/bin",
},
"pathToRDebugIDE": "/home/ales/.gem/ruby/2.6.0/bin/rdebug-ide"
}
]
@AlesLulak Thanks, but I have already put the proper $PATH in the configuration and it didnβt work. In addition, I think pathToRDebugIDE was supposed to remove the need of modifying the $PATH at all.
For all people hitting this error on Windows, despite adding PATH to ENV in launch.json, mind this: https://stackoverflow.com/a/54993121/717732 - check the spelling of PATH on your OS!
anyone share lauch.json with rbenv?
@nighttiger1990 I use uru instead of rbenv, the idea is similar. I have not found ANY way to run uru-based commandline instead of plain ruby executable. Therefore, my launch.json looks like this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Local File",
"type": "Ruby",
"request": "launch",
"env": {
"Path": "c:/rubies/Ruby26-x64/bin"
},
"cwd": "${workspaceRoot}",
"program": "${file}"
}
]
}
notable bits:
Path variable name is case sensitive, even on Windows; when I had PATH or path it didn't work properlybin folder, that's because VSCODE simply runs ruby.exe and expects it to be "just obviously available"cwd and program are set to what I like to have, it works with whatever reasonable thing you put thereprogram variable to something like "run uru/rbenv and then run run my script" because the program is prepended with ruby.exe and then debugger may try to attach to it; ruby.exe name seems not configurable; debugger-attaching behavior seems not configurableHere is a quick bash printf command to give you the required env details to place into
launch.jsonprintf "\n\"env\": {\n \"PATH\": \"$PATH\",\n \"GEM_HOME\": \"$GEM_HOME\",\n \"GEM_PATH\": \"$GEM_PATH\",\n \"RUBY_VERSION\": \"$RUBY_VERSION\"\n}\n\n"
Thank you!!!
In my case, I need to use Path instead of PATH. IDK why
printf "\n\"env\": {\n \"Path\": \"$PATH\",\n \"GEM_HOME\": \"$GEM_HOME\",\n \"GEM_PATH\": \"$GEM_PATH\",\n \"RUBY_VERSION\": \"$RUBY_VERSION\"\n}\n\n"
Most helpful comment
Here is a quick bash printf command to give you the required env details to place into
launch.json