Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

"Debugger terminal error: Process failed: spawn rdebug-ide ENOENT" when trying to debug #214

Closed
mattwelke opened this issue Oct 9, 2017 · 25 comments

Comments

@mattwelke
Copy link

mattwelke commented Oct 9, 2017

Your environment

  • vscode-ruby version: 0.15.0
  • Ruby version: 2.4.2
  • VS Code version: 1.16.1
  • Operating System: Antergos
  • Hardware (optional): Intel Core i5 system with integrated Intel graphics

Make 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.

Expected behavior

Able to launch debugging.

Actual behavior

Debugging doesn't launch. VS Code output console says:

Debugger terminal error: Process failed: spawn rdebug-ide ENOENT

Steps to reproduce the problem

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.

@mattwelke
Copy link
Author

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?

@aryeh-looker
Copy link

aryeh-looker commented Oct 10, 2017

+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.

@taylorthurlow
Copy link

taylorthurlow commented Nov 10, 2017

@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"
}

@vzamanillo
Copy link

vzamanillo commented Nov 12, 2017

Based on this comment, #62 (comment) 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.

@wingrunr21
Copy link
Collaborator

Closing for issue cleanup. Apologies if this is still an issue. We are working to improve the core extension experience.

@timkrins
Copy link

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"

@leggettc18
Copy link

leggettc18 commented Jul 30, 2018

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.

@jannik-mohemian
Copy link

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?

@alexventuraio
Copy link

@leggettc18 can you share your launch.json config file for reference for people who is working with rbenv, please?

@et
Copy link

et commented Nov 2, 2018

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"
      }
    }
  ]
}

@ryano3000
Copy link

very helpful thanks!

@fiznool
Copy link

fiznool commented Jan 8, 2019

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.

@Lucius3451
Copy link

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

can you run rdebug-ide xx.rb directly in cmd? If you can do that, it might mean Code doesn't take your env, so you can try to launch VS Code from command line and debug again.

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.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"

@FranklinYu
Copy link
Contributor

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?

@AlesLulak
Copy link

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 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"
       }
    ]

@FranklinYu
Copy link
Contributor

FranklinYu commented Apr 6, 2019

@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.

@quetzalcoatl
Copy link

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!

@nighttiger1990
Copy link

anyone share lauch.json with rbenv?

@quetzalcoatl
Copy link

quetzalcoatl commented Mar 11, 2020

@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 properly
  • I have to set Path manually to correct ruby version bin 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 there
  • it doesn't seem possible to hack program 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 configurable

@piradata
Copy link

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"

Thank you!!!

@fifiteen82726
Copy link

fifiteen82726 commented Jan 26, 2021

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"

@ntad15
Copy link

ntad15 commented Dec 4, 2021

Even though i see ruby-debug-ide in the gem list, when i do "which ruby-debug-ide" it doesn't recognize it.
It keeps saying command not found

@josealvarez97
Copy link

josealvarez97 commented Oct 3, 2022

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.

— worked like a charm. Found this Stack Overflow question helpful as well https://stackoverflow.com/a/56810833/8062488

@gbisheimer
Copy link

I've just installed rbenv and found that I have no $GEM_PATH nor $GEM_HOME env vars. So, had to use this workaround:

printf "\n\"env\": {\n \"PATH\": \"$PATH\",\n \"GEM_HOME\": \"$(gem env home)\",\n \"GEM_PATH\": \"$(gem env path)\",\n \"RUBY_VERSION\": \"$(ruby -v)\"\n}\n\n"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests