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

Unable to debug python with node 13 environment. "Number of constructor arguments..." #105

Closed
BlueDrink9 opened this issue Jan 30, 2020 · 17 comments · Fixed by #108
Closed

Comments

@BlueDrink9
Copy link

Describe the bug

Starting to debug a basic python file opens vimspector windows but no debugging starts. Vimspector encounters an error and crashes.

To Reproduce

  • vim test.py
  • iprint('hello')
  • <f5>

Vimspector config file:

{
  "configurations": {
    "univisal: Launch": {
      "adapter": "vscode-python",
      "configuration": {
        "name": "<name>: Launch",
        "type": "python",
        "request": "launch",
        "cwd": "${workspaceRoot}",
        "stopOnEntry": true,
        "console": "externalTerminal",
        "debugOptions": [],
        "program": "${file}"
      }
    }
  }
}

Expected behavior

A debugging session starts

Actual behaviour

Vimspector windows open but no debugging starts.

No output except stderr, and that was the same as the contents of the log.

Environemnt

  • Version of Vimspector: (e.g. output of git rev-parse HEAD if cloned or the
    name of the tarball used to install otherwise)

c6c0144

  • Output of vim --version or nvim --version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Jan 26 2020 11:45:38)
Included patches: 1-148
Compiled by Arch Linux
Huge version with GTK3 GUI.  Features included (+) or not (-):
+acl               -farsi             -mouse_sysmouse    -tag_old_static
+arabic            +file_in_path      +mouse_urxvt       -tag_any_white
+autocmd           +find_in_path      +mouse_xterm       +tcl/dyn
+autochdir         +float             +multi_byte        +termguicolors
-autoservername    +folding           +multi_lang        +terminal
+balloon_eval      -footer            -mzscheme          +terminfo
+balloon_eval_term +fork()            +netbeans_intg     +termresponse
+browse            +gettext           +num64             +textobjects
++builtin_terms    -hangul_input      +packages          +textprop
+byte_offset       +iconv             +path_extra        +timers
+channel           +insert_expand     +perl/dyn          +title
+cindent           +job               +persistent_undo   +toolbar
+clientserver      +jumplist          +popupwin          +user_commands
+clipboard         +keymap            +postscript        +vartabs
+cmdline_compl     +lambda            +printer           +vertsplit
+cmdline_hist      +langmap           +profile           +virtualedit
+cmdline_info      +libcall           +python/dyn        +visual
+comments          +linebreak         +python3/dyn       +visualextra
+conceal           +lispindent        +quickfix          +viminfo
+cryptv            +listcmds          +reltime           +vreplace
+cscope            +localmap          +rightleft         +wildignore
+cursorbind        +lua/dyn           +ruby/dyn          +wildmenu
+cursorshape       +menu              +scrollbind        +windows
+dialog_con_gui    +mksession         +signs             +writebackup
+diff              +modify_fname      +smartindent       +X11
+digraphs          +mouse             +sound             -xfontset
+dnd               +mouseshape        +spell             +xim
-ebcdic            +mouse_dec         +startuptime       -xpm
+emacs_tags        +mouse_gpm         +statusline        +xsmp_interact
+eval              -mouse_jsbterm     -sun_workshop      +xterm_clipboard
+ex_extra          +mouse_netterm     +syntax            -xterm_save
+extra_search      +mouse_sgr         +tag_binary        
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "/etc/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -I/usr/include/gtk-3.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/lib/libffi-3.2.1/include -I/usr/include/harfbuzz -I/usr/include/fribidi -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/gio-unix-2.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include -pthread    -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -D_REENTRANT  -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: gcc   -L. -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.30/core_perl/CORE  -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -L/usr/local/lib -Wl,--as-needed -o vim   -lgtk-3 -lgdk-3 -lz -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0  -lSM -lICE -lXt -lX11 -lXdmcp -lSM -lICE  -lm -ltinfo -lelf -lnsl    -lcanberra  -lacl -lattr -lgpm -ldl   -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.30/core_perl/CORE -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fstack-protector-strong -L/usr/local/lib  -L/usr/lib/perl5/5.30/core_perl/CORE -lperl -lpthread -ldl -lm -lcrypt -lutil -lc   -L/usr/lib -ltclstub8.6 -ldl -lz -lpthread -lm     
  • Output of which vim or which nvim:
/usr/bin/vim
  • Output of :py3 pass: no output

  • Output of :py3 import vim: No output

  • Operating system: Arch linux updated today

Vimspector.log:

2020-01-30 21:51:13,867 - INFO - **** INITIALISING NEW VIMSPECTOR SESSION ****
2020-01-30 21:51:13,867 - INFO - API is: 
2020-01-30 21:51:13,867 - INFO - VIMSPECTOR_HOME = /home/user/.vim/plugins/vimspector
2020-01-30 21:51:13,868 - INFO - gadgetDir = /home/user/.vim/plugins/vimspector/gadgets/linux
2020-01-30 21:52:20,008 - INFO - User requested start debug session with {}
2020-01-30 21:52:20,009 - DEBUG - Reading gadget config: /home/user/.vim/plugins/vimspector/gadgets/linux/.gadgets.json
2020-01-30 21:52:20,010 - DEBUG - Reading gadget config: None
2020-01-30 21:52:20,011 - INFO - Configuration: {"adapter": "vscode-python", "configuration": {"name": "<name>: Launch", "type": "python", "request": "launch", "cwd": "/home/user/src/Univisal", "stopOnEntry": true, "console": "externalTerminal", "debugOptions": [], "program": "/home/user/src/Univisal/test.py"}}
2020-01-30 21:52:20,011 - INFO - Adapter: {"command": ["node", "/home/user/.vim/plugins/vimspector/gadgets/linux/vscode-python/out/client/debugger/debugAdapter/main.js"], "name": "vscode-python"}
2020-01-30 21:52:20,444 - INFO - Starting debug adapter with: {"command": ["node", "/home/user/.vim/plugins/vimspector/gadgets/linux/vscode-python/out/client/debugger/debugAdapter/main.js"], "name": "vscode-python"}
2020-01-30 21:52:20,534 - INFO - Debug Adapter Started
2020-01-30 21:52:20,534 - DEBUG - Sending Message: {"command": "initialize", "arguments": {"adapterID": "vscode-python", "clientID": "vimspector", "clientName": "vimspector", "linesStartAt1": true, "columnsStartAt1": true, "locale": "en_GB", "pathFormat": "path", "supportsVariableType": true, "supportsVariablePaging": false, "supportsRunInTerminalRequest": true}, "seq": 0, "type": "request"}
2020-01-30 21:52:20,534 - DEBUG - Calling: vimspector#internal#job#Send(g:vimspector_internal_arg_0)
2020-01-30 21:52:20,566 - DEBUG - Message received: {'seq': 0, 'type': 'event', 'event': 'error', 'body': 'Debugger Error: The number of constructor arguments in the derived class s must be >= than the number of constructor arguments of its base class.'}
2020-01-30 21:52:20,567 - WARNING - User Msg: Unhandled event: error
2020-01-30 21:52:20,567 - DEBUG - Message received: {'seq': 0, 'type': 'event', 'event': 'output', 'body': {'category': 'stderr', 'output': 'Debugger Error: The number of constructor arguments in the derived class s must be >= than the number of constructor arguments of its base class.\nDebugger Error: The number of constructor arguments in the derived class s must be >= than the number of constructor arguments of its base class.\nError\nError: The number of constructor arguments in the derived class s must be >= than the number of constructor arguments of its base class.\n    at /home/user/.vim/plugins/vimspector/gadgets/linux/download/vscode-python/2019.11.50794/root/extension/out/client/debugger/debugAdapter/main.js:16:27311\n    at Array.forEach (<anonymous>)\n    at e (/home/user/.vim/plugins/vimspector/gadgets/linux/download/vscode-python/2019.11.50794/root/extension/out/client/debugger/debugAdapter/main.js:16:26875)\n    at Object.t.plan (/home/user/.vim/plugins/vimspector/gadgets/linux/download/vscode-python/2019.11.50794/root/extension/out/client/debugger/debugAdapter/main.js:16:27386)\n    at /home/user/.vim/plugins/vimspector/gadgets/linux/download/vscode-python/2019.11.50794/root/extension/out/client/debugger/debugAdapter/main.js:16:24044\n    at e._get (/home/user/.vim/plugins/vimspector/gadgets/linux/download/vscode-python/2019.11.50794/root/extension/out/client/debugger/debugAdapter/main.js:16:23953)\n    at e.get (/home/user/.vim/plugins/vimspector/gadgets/linux/download/vscode-python/2019.11.50794/root/extension/out/client/debugger/debugAdapter/main.js:16:22664)\n    at s.get (/home/user/.vim/plugins/vimspector/gadgets/linux/download/vscode-python/2019.11.50794/root/extension/out/client/debugger/debugAdapter/main.js:68:141080)\n    at new _ (/home/user/.vim/plugins/vimspector/gadgets/linux/download/vscode-python/2019.11.50794/root/extension/out/client/debugger/debugAdapter/main.js:1:268522)\n    at /home/user/.vim/plugins/vimspector/gadgets/linux/download/vscode-python/2019.11.50794/root/extension/out/client/debugger/debugAdapter/main.js:1:271764'}}
2020-01-30 21:52:20,603 - INFO - The server has terminated with status 0
2020-01-30 21:52:20,603 - DEBUG - Closing down: Aborting request {'command': 'initialize', 'arguments': {'adapterID': 'vscode-python', 'clientID': 'vimspector', 'clientName': 'vimspector', 'linesStartAt1': True, 'columnsStartAt1': True, 'locale': 'en_GB', 'pathFormat': 'path', 'supportsVariableType': True, 'supportsVariablePaging': False, 'supportsRunInTerminalRequest': True}, 'seq': 0, 'type': 'request'}
2020-01-30 21:52:20,603 - INFO - User Msg: Request for initialize aborted: Closing down
2020-01-30 21:52:20,637 - DEBUG - No server exit handler
2020-01-30 21:52:23,597 - INFO - Debugging complete.
2020-01-30 21:52:23,598 - DEBUG - Clearing down UI with stack_trace: ['  File "<string>", line 1, in <module>\n', '  File "/home/user/.vim//plugins/vimspector/python3/vimspector/debug_session.py", line 300, in Reset\n    self._Reset()\n', '  File "/home/user/.vim//plugins/vimspector/python3/vimspector/debug_session.py", line 306, in _Reset\n    traceback.format_stack() )\n']
@puremourning
Copy link
Owner

You need to use node < 13. I recommend nvm use 10

This is a bug/incompatibility of the python debug adapter from Microsoft

@BlueDrink9
Copy link
Author

The debugger works in vscode though, is that expected with node > 13?

@puremourning
Copy link
Owner

I expect vscode is bundling node. You need a version of node that will run the DA.

@puremourning
Copy link
Owner

All vimspector is doing is running this:

"node" "/Users/eyalkarni/vimpy3/pack/vimspector/opt/vimspector/gadgets/macos/vscode-python/out/client/debugger/debugAdapter/main.js”

If you can see vscode doing something different let me know.

@puremourning
Copy link
Owner

re-opening as this doesn't affect VSCode and there's a meaninful possibility that https://github.com/microsoft/vscode-python/issues/9829 won't be fixed.

@puremourning puremourning reopened this Jan 30, 2020
@puremourning
Copy link
Owner

puremourning commented Jan 30, 2020

There is however a workaround, you can use ptvsd directly instead of vscode-python. It requires different launch configuration, but it does work and doesn't rely on nodejs.

You'll have to work out the adapter configuration for that yourself, but i think this is where the vscode-python starts up ptvsd

@BlueDrink9
Copy link
Author

Thanks, I'll take a look at this later

@BlueDrink9
Copy link
Author

I might take a look at configuring it myself, but I didn't understand much of what was being said in the ptvsd thread, so it'll be a dedicated project in itself some other time.

Is there much chance you will end up switching it yourself once the standalone version is released?

@puremourning puremourning changed the title Vimspector crashes trying to debug python. "Number of constructor arguments..." Unable to debug python with node 13 environment. "Number of constructor arguments..." Jan 31, 2020
@puremourning
Copy link
Owner

puremourning commented Jan 31, 2020

Here's how to make it work with debugpy :

Alternative: Use debugpy directly

If you can't get a node 10 envirinment set up for whatver reason, then you can
avoid that issue by using debugpy (formerly ptvsd directly).

Here's how:

  1. Instal debugpy: pip install debugpy
  2. Create /path/to/vimspector/gadgets/<os>/.gadgets.d/debugpy.json:
{
  "adapters": {
    "debugpy": {
      "command": [
        "python",
        "-m",
        "debugpy.adapter"
      ],
      "name": "debugpy",
      "configuration": {
        "python": "python"
      }
    }
  }
}

Then in theory you should just have to change "adapter": "vscode-python" to
"adapter": "debugpy".

I tested this and it works for me.

@BlueDrink9
Copy link
Author

Thank you!

@BlueDrink9
Copy link
Author

I understand that neovim isn't really supported, but this particular adapter worked fine on vim but not neovim. Are you willing to offer any suggestions?

E+00000.022: Error parsing 'DEBUGPY_LAUNCHER_POR
T':

             Traceback (most recent call last):
               File "/home/user/.local/lib/py
thon3.8/site-packages/debugpy/launcher/__main__.
py", line 36, in option
                 return type(os.environ.pop(name
, *args))
               File "/usr/lib/python3.8/_collect
ions_abc.py", line 795, in pop
                 value = self[key]
               File "/usr/lib/python3.8/os.py",
line 673, in __getitem__
                 raise KeyError(key) from None
             KeyError: 'DEBUGPY_LAUNCHER_PORT'

             Stack where logged:
               File "/usr/lib/python3.8/runpy.py
", line 193, in _run_module_as_main
                 return _run_code(code, main_glo
bals, None,
               File "/usr/lib/python3.8/runpy.py
", line 86, in _run_code
                 exec(code, run_globals)
               File "/home/user/.local/lib/py
thon3.8/site-packages/debugpy/launcher/__main__.
py", line 80, in <module>
                 main()
               File "/home/user/.local/lib/py
thon3.8/site-packages/debugpy/launcher/__main__.
py", line 40, in main
                 launcher_port = option("DEBUGPY
_LAUNCHER_PORT", int)
               File "/home/user/.local/lib/py
thon3.8/site-packages/debugpy/launcher/__main__.
py", line 38, in option
                 raise log.exception("Error pars
ing {0!r}:", name)


Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 193,
in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 86, i
n _run_code
    exec(code, run_globals)
  File "/home/user/.local/lib/python3.8/site-
packages/debugpy/launcher/__main__.py", line 80,
 in <module>
    main()
  File "/home/user/.local/lib/python3.8/site-
packages/debugpy/launcher/__main__.py", line 40,
 in main
    launcher_port = option("DEBUGPY_LAUNCHER_POR
T", int)
  File "/home/user/.local/lib/python3.8/site-
packages/debugpy/launcher/__main__.py", line 38,
 in option
    raise log.exception("Error parsing {0!r}:",
name)
  File "/home/user/.local/lib/python3.8/site-
packages/debugpy/launcher/__main__.py", line 36,
 in option
    return type(os.environ.pop(name, *args))
  File "/usr/lib/python3.8/_collections_abc.py",
 line 795, in pop
    value = self[key]
  File "/usr/lib/python3.8/os.py", line 673, in
__getitem__
    raise KeyError(key) from None
KeyError: 'DEBUGPY_LAUNCHER_PORT'

[Process exited 1]

@puremourning
Copy link
Owner

Please see the note in the README.

@puremourning
Copy link
Owner

puremourning commented Feb 1, 2020

#108 (comment)

It’s a(nother) neovim missing feature. Apparently it works with master but 🤷‍♂️

@puremourning
Copy link
Owner

I pushed a PR to make it work in neovim. le sigh.

@BlueDrink9
Copy link
Author

Way of the future

@juanMarinero
Copy link

TL;DR TLDR (Vim only, no NeoVim)

  • Vim >= 8.2 && Node >= 11
$ [[ $(vim --version 2>&1) =~ "Vi IMproved 8."[2-9] ]] || echo "update VIM"
$ [[ $(node --version 2>&1) =~ v1[1-9] ]] || echo "update Node OR follow no more steps of this github-comment"
  • Install Plug, see docu
    E.g. if junegunn/vim-plug: add Plug 'puremourning/vimspector' to ~/.vimrc. Run :PlugInstall. Run :source ~/.vimrc

  • do NOT run :VimspectorInstall debugpy

  • debug with venv-debugpy
    Create /path/to/vimspector/gadgets/<os>/.gadgets.d/debugpy.json
    E.g. if vim-plugger junegunn/vim-plug && OS GNU-Linux:

$ dir01="$HOME/.vim/plugged/vimspector/gadgets/linux/.gadgets.d" 
$ mkdir -p $dir01  
$ vim $dir01/debugpy.json

Paste and save:

{
  "adapters": {
    "debugpy": {
      "command": [
        "python",
        "-m",
        "debugpy.adapter"
      ],
      "name": "debugpy",
      "configuration": {
        "python": "python"
      }
    }
  }
}
  • $ [activate venv] && pip3 install debugpy --> !!! in every new venv !!!

  • $ vim [projectDirectory]/.vimspector.json --> !!! in every new project !!!
    Paste and save:

{
  "configurations": {
    "univisal: Launch": {
      "adapter": "debugpy",
      "configuration": {
        "name": "<name>: Launch",
        "type": "python",
        "request": "launch",
        "cwd": "${workspaceRoot}",
        "stopOnEntry": true,
        "console": "externalTerminal",
        "debugOptions": [],
        "program": "${file}"
      }
    }
  }
}
  • $ vim [py file] and activate venv (where you pip-installed debugpy)
    E.g. jmcantrell/vim-virtualenv --> :VirtualEnvActivate <tab>

  • launch the awesome Vimspector --> :call vimspector#Launch()

@puremourning
Copy link
Owner

Why? Or just use vimspector to install debugpy. What is the purpose of all that effort?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants