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

Vim:E158: Invalid buffer name <name> when starting debugging in neovim #131

Closed
RonanMacF opened this issue Mar 7, 2020 · 10 comments
Closed

Comments

@RonanMacF
Copy link

RonanMacF commented Mar 7, 2020

Describe the bug
Debugging is perfect in vim, when I try to do it in neovim I get the following error

uncaught: Break on Uncaught Exceptions (Y/N/default: Y)? YError detected while processing function <SNR>109__OnEvent[3]..provider#python3#Call:
line   18:
Error invoking 'python_execute' on channel 6 (python3-script-host):
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/ronan/.vim/plugged/vimspector/python3/vimspector/debug_session.py", line 286, in OnChannelData
    self._connection.OnData( data )
  File "/Users/ronan/.vim/plugged/vimspector/python3/vimspector/debug_adapter_connection.py", line 158, in OnData
    self._ReadBody()
  File "/Users/ronan/.vim/plugged/vimspector/python3/vimspector/debug_adapter_connection.py", line 232, in _ReadBody
    self._OnMessageReceived( message )
  File "/Users/ronan/.vim/plugged/vimspector/python3/vimspector/debug_adapter_connection.py", line 276, in _OnMessageReceived
    getattr( self._handler, method )( message )
  File "/Users/ronan/.vim/plugged/vimspector/python3/vimspector/debug_session.py", line 826, in OnEvent_initialized
    self._breakpoints.SendBreakpoints( onBreakpointsDone )
  File "/Users/ronan/.vim/plugged/vimspector/python3/vimspector/breakpoints.py", line 232, in SendBreakpoints
    self._SignToLine( file_name, bp )
  File "/Users/ronan/.vim/plugged/vimspector/python3/vimspector/breakpoints.py", line 371, in _SignToLine
    json.dumps( { 'id': file_name, 'group': 'VimspectorBP', } ) ) )
  File "/usr/local/lib/python3.7/site-packages/pynvim/plugin/script_host.py", line 207, in eval
    obj = self.request("vim_eval", expr)
  File "/usr/local/lib/python3.7/site-packages/pynvim/api/nvim.py", line 182, in request
    res = self._session.request(name, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/pynvim/msgpack_rpc/session.py", line 104, in request
    raise self.error_wrapper(err)
pynvim.api.common.NvimError: Vim:E158: Invalid buffer name: /Users/ronan/tmp/tm.py

To Reproduce
Open pythin file, place a breakpoing using f9, start deubber using f5

Vimspector config file:

{
    "configurations": {
      "<name>: Launch": {
        "adapter": "debugpy",
        "configuration": {
          "name": "<name>: Launch",
          "type": "python",
          "request": "launch",
          "cwd": "${workspaceRoot}",
          "python": "/usr/local/bin/python3",
          "stopOnEntry": true,
          "console": "externalTerminal",
          "debugOptions": [],
          "program": "${file}"
      }
    }
  }
  }

Expected behavior
Debugger to work as per normal

2020-03-07 21:55:10,629 - INFO - **** INITIALISING NEW VIMSPECTOR SESSION ****
2020-03-07 21:55:10,629 - INFO - API is: neo
2020-03-07 21:55:10,629 - INFO - VIMSPECTOR_HOME = /Users/ronan/.vim/plugged/vimspector
2020-03-07 21:55:10,639 - INFO - gadgetDir = /Users/ronan/.vim/plugged/vimspector/gadgets/macos
2020-03-07 21:55:10,642 - DEBUG - Toggle found bp at /Users/ronan/tmp/tm.py:3 ? False (New)
2020-03-07 21:55:12,878 - INFO - User requested start debug session with {}
2020-03-07 21:55:12,879 - DEBUG - Reading gadget config: /Users/ronan/.vim/plugged/vimspector/gadgets/macos/.gadgets.json
2020-03-07 21:55:12,883 - DEBUG - Reading gadget config: None
2020-03-07 21:55:12,884 - DEBUG - Reading configurations from: None
2020-03-07 21:55:12,884 - DEBUG - Reading configurations from: /Users/ronan/tmp/.vimspector.json
2020-03-07 21:55:12,885 - INFO - Configuration: {"adapter": "debugpy", "configuration": {"name": "<name>: Launch", "type": "python", "request": "launch", "cwd": "/Users/ronan/tmp", "python": "/usr/local/bin/python3", "stopOnEntry": true, "console": "externalTerminal", "debugOptions": [], "program": "/Users/ronan/tmp/tm.py"}}
2020-03-07 21:55:12,885 - INFO - Adapter: {"command": ["/usr/local/opt/python/bin/python3.7", "/Users/ronan/.vim/plugged/vimspector/gadgets/macos/debugpy/build/lib/debugpy/adapter"], "configuration": {"python": "/usr/local/opt/python/bin/python3.7"}, "name": "debugpy"}
2020-03-07 21:55:13,325 - INFO - Starting debug adapter with: {"command": ["/usr/local/opt/python/bin/python3.7", "/Users/ronan/.vim/plugged/vimspector/gadgets/macos/debugpy/build/lib/debugpy/adapter"], "configuration": {"python": "/usr/local/opt/python/bin/python3.7"}, "name": "debugpy"}
2020-03-07 21:55:13,329 - INFO - Debug Adapter Started
2020-03-07 21:55:13,330 - DEBUG - Sending Message: {"command": "initialize", "arguments": {"adapterID": "debugpy", "clientID": "vimspector", "clientName": "vimspector", "linesStartAt1": true, "columnsStartAt1": true, "locale": "en_GB", "pathFormat": "path", "supportsVariableType": true, "supportsVariablePaging": false, "supportsRunInTerminalRequest": true}, "seq": 0, "type": "request"}
2020-03-07 21:55:13,330 - DEBUG - Calling: vimspector#internal#neojob#Send(g:vimspector_internal_arg_0)
2020-03-07 21:55:13,509 - DEBUG - Message received: {'seq': 1, 'type': 'event', 'event': 'output', 'body': {'category': 'telemetry', 'output': 'ptvsd', 'data': {'packageVersion': '0+untagged.1.gb7dee64'}}}
2020-03-07 21:55:13,566 - DEBUG - Message received: {'seq': 3, 'type': 'response', 'request_seq': 0, 'success': True, 'command': 'initialize', 'body': {'supportsCompletionsRequest': True, 'supportsConditionalBreakpoints': True, 'supportsConfigurationDoneRequest': True, 'supportsDebuggerProperties': True, 'supportsDelayedStackTraceLoading': True, 'supportsEvaluateForHovers': True, 'supportsExceptionInfoRequest': True, 'supportsExceptionOptions': True, 'supportsHitConditionalBreakpoints': True, 'supportsLogPoints': True, 'supportsModulesRequest': True, 'supportsSetExpression': True, 'supportsSetVariable': True, 'supportsValueFormattingOptions': True, 'supportsTerminateDebuggee': True, 'supportsGotoTargetsRequest': True, 'exceptionBreakpointFilters': [{'filter': 'raised', 'label': 'Raised Exceptions', 'default': False}, {'filter': 'uncaught', 'label': 'Uncaught Exceptions', 'default': True}]}}
2020-03-07 21:55:13,566 - DEBUG - LAUNCH!
2020-03-07 21:55:13,567 - DEBUG - Sending Message: {"command": "launch", "arguments": {"python": "/usr/local/bin/python3", "name": "<name>: Launch", "type": "python", "request": "launch", "cwd": "/Users/ronan/tmp", "stopOnEntry": true, "console": "externalTerminal", "debugOptions": [], "program": "/Users/ronan/tmp/tm.py"}, "seq": 1, "type": "request"}
2020-03-07 21:55:13,567 - DEBUG - Calling: vimspector#internal#neojob#Send(g:vimspector_internal_arg_0)
2020-03-07 21:55:13,567 - DEBUG - Message received: {'seq': 2, 'type': 'event', 'event': 'output', 'body': {'category': 'telemetry', 'output': 'debugpy', 'data': {'packageVersion': '0+untagged.1.gb7dee64'}}}
2020-03-07 21:55:13,625 - DEBUG - Message received: {'seq': 4, 'type': 'request', 'command': 'runInTerminal', 'arguments': {'kind': 'external', 'title': 'Python Debug Console', 'args': ['/usr/local/opt/python/bin/python3.7', '/Users/ronan/.vim/plugged/vimspector/gadgets/macos/debugpy/build/lib/debugpy/launcher', '/Users/ronan/tmp/tm.py'], 'env': {'DEBUGPY_LAUNCHER_PORT': '62959'}}}
2020-03-07 21:55:13,625 - DEBUG - Defaulting working directory to /Users/ronan/tmp
2020-03-07 21:55:13,656 - DEBUG - Calling: vimspector#internal#neoterm#Start(g:vimspector_internal_arg_0, g:vimspector_internal_arg_1)
2020-03-07 21:55:13,716 - DEBUG - Calling: vimspector#internal#neoterm#GetPID(g:vimspector_internal_arg_0)
2020-03-07 21:55:13,716 - DEBUG - Sending Message: {"seq": 2, "type": "response", "request_seq": 4, "command": "runInTerminal", "body": {"processId": 25568}, "success": true}
2020-03-07 21:55:13,716 - DEBUG - Calling: vimspector#internal#neojob#Send(g:vimspector_internal_arg_0)
2020-03-07 21:55:14,378 - DEBUG - Message received: {'seq': 5, 'type': 'event', 'event': 'initialized'}
2020-03-07 21:55:56,574 - DEBUG - Timeout: Aborting request {'command': 'launch', 'arguments': {'python': '/usr/local/bin/python3', 'name': '<name>: Launch', 'type': 'python', 'request': 'launch', 'cwd': '/Users/ronan/tmp', 'stopOnEntry': True, 'console': 'externalTerminal', 'debugOptions': [], 'program': '/Users/ronan/tmp/tm.py'}, 'seq': 1, 'type': 'request'}
2020-03-07 21:55:56,575 - INFO - User Msg: Request for launch aborted: Timeout

Actual behaviour

Please include:

  • Vimspector log (~/.vimspector.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)
    'b7dee64'

  • Output of vim --version or nvim --version

NVIM v0.4.3
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/local/Homebrew/Library/Homebrew/shims/mac/super/clang -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/tmp/neovim-20191107-85913-1wbgqz6/neovim-0.4.3/build/config -I/tmp/neovim-20191107-85913-1wbgqz6/neovim-0.4.3/src -I/usr/local/include -I/tmp/neovim-20191107-85913-1wbgqz6/neovim-0.4.3/deps-build/include -I/usr/local/opt/gettext/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include -I/tmp/neovim-20191107-85913-1wbgqz6/neovim-0.4.3/build/src/nvim/auto -I/tmp/neovim-20191107-85913-1wbgqz6/neovim-0.4.3/build/include```
  • Output of which vim or which nvim:
/usr/local/bin/nvim

  • Output of :py3 pass:
Nothing happens
  • Output of :py3 import vim:
also nothing
  • For neovim: output of :checkhealth
health#coc#check
========================================================================
  - OK: Environment check passed

  - OK: Javascript bundle found
  - OK: Service started

health#nvim#check
========================================================================
## Configuration
  - OK: no issues found

## Performance
  - OK: Build type: Release

## Remote Plugins
  - OK: Up to date

## terminal
  - INFO: key_backspace (kbs) terminfo entry: key_backspace=^H
  - INFO: key_dc (kdch1) terminfo entry: key_dc=\E[3~
  - INFO: $TERM_PROGRAM='iTerm.app'
  - INFO: $COLORTERM='truecolor'

health#provider#check
========================================================================
## Clipboard (optional)
  - OK: Clipboard tool found: pbcopy

## Python 2 provider (optional)
  - INFO: `g:python_host_prog` is not set.  Searching for python2 in the environment.
  - INFO: Executable: /usr/bin/python2
  - INFO: Python version: 2.7.16
  - INFO: pynvim version: 0.4.1
  - OK: Latest pynvim is installed.

## Python 3 provider (optional)
  - INFO: Using: g:python3_host_prog = "/usr/local/bin/python3"
  - INFO: Executable: /usr/local/bin/python3
  - INFO: Python version: 3.7.6
  - INFO: pynvim version: 0.4.1
  - OK: Latest pynvim is installed.

## Ruby provider (optional)
  - INFO: Ruby: ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
  - WARNING: `neovim-ruby-host` not found.
    - ADVICE:
      - Run `gem install neovim` to ensure the neovim RubyGem is installed.
      - Run `gem environment` to ensure the gem bin directory is in $PATH.
      - If you are using rvm/rbenv/chruby, try "rehashing".
      - See :help |g:ruby_host_prog| for non-standard gem installations.

## Node.js provider (optional)
  - INFO: Node.js: v12.16.0
  - INFO: Neovim node.js host: /usr/local/lib/node_modules/neovim/bin/cli.js
  - OK: Latest "neovim" npm/yarn package is installed: 4.8.0

  • Operating system: and version
    Macos catalina 10.15.3
    Additional context
    Add any other context about the problem here.
@puremourning
Copy link
Owner

Can you please try with a minimal vimrc and the simple example in /path/to/vimspector/support/test/python/simple_python/main.py ? i.e.:

  • cd /path/to/vimspector
  • nvim -Nu tests/vimrc --cmd 'let g:vimspector_enabe_mappings="HUMAN"' support/test/python/simple_python/main.py
  • set a breakpoint (<F9>)
  • <F5>
  • select 'run'

I can't repro with that.

You might need to use a custom minimal vimrc because neovimn is a pain in the gut when it comes to python (for example, I use this):

let g:python_host_prog=expand( '$HOME/.pyenv/versions/nvim2/bin/python' )
let g:python3_host_prog=expand( '$HOME/.pyenv/versions/nvim3/bin/python' )

let s:vimspector_path = expand( '<sfile>:p:h' ) " change this 
let g:vimspector_enable_mappings = 'HUMAN'
exe 'source ' . s:vimspector_path . '/tests/vimrc'

@RonanMacF
Copy link
Author

Have attempted the single command and it gives the following prompt one I run it

Which launch configuration?
1: attach
2: run
3: run legacy vscode-python

Attaching gives the following result.

Error detected while processing function vimspector#Continue[1]..provider#python3#Call:
line   18:
Error invoking 'python_execute' on channel 3 (python3-script-host):
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/ronan/dotfiles/vim/.vim/plugged/vimspector/python3/vimspector/debug_session.py", line 374, in Continue
    self.Start()
  File "/Users/ronan/dotfiles/vim/.vim/plugged/vimspector/python3/vimspector/debug_session.py", line 195, in Start
    utils.ParseVariables( adapter.get( 'variables', {} ),
AttributeError: 'NoneType' object has no attribute 'get'

Clicking option 2, run, gives the following

Error detected while processing function <SNR>32__OnEvent[3]..provider#python3#Call:
line   18:
Error invoking 'python_execute' on channel 3 (python3-script-host):
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/ronan/dotfiles/vim/.vim/plugged/vimspector/python3/vimspector/debug_session.py", line 286, in OnChannelData
    self._connection.OnData( data )
  File "/Users/ronan/dotfiles/vim/.vim/plugged/vimspector/python3/vimspector/debug_adapter_connection.py", line 158, in OnData
    self._ReadBody()
  File "/Users/ronan/dotfiles/vim/.vim/plugged/vimspector/python3/vimspector/debug_adapter_connection.py", line 232, in _ReadBody
    self._OnMessageReceived( message )
  File "/Users/ronan/dotfiles/vim/.vim/plugged/vimspector/python3/vimspector/debug_adapter_connection.py", line 276, in _OnMessageReceived
    getattr( self._handler, method )( message )
  File "/Users/ronan/dotfiles/vim/.vim/plugged/vimspector/python3/vimspector/debug_session.py", line 826, in OnEvent_initialized
    self._breakpoints.SendBreakpoints( onBreakpointsDone )
  File "/Users/ronan/dotfiles/vim/.vim/plugged/vimspector/python3/vimspector/breakpoints.py", line 232, in SendBreakpoints
    self._SignToLine( file_name, bp )
  File "/Users/ronan/dotfiles/vim/.vim/plugged/vimspector/python3/vimspector/breakpoints.py", line 371, in _SignToLine
    json.dumps( { 'id': file_name, 'group': 'VimspectorBP', } ) ) )
  File "/usr/local/lib/python3.7/site-packages/pynvim/plugin/script_host.py", line 207, in eval
    obj = self.request("vim_eval", expr)
  File "/usr/local/lib/python3.7/site-packages/pynvim/api/nvim.py", line 182, in request
    res = self._session.request(name, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/pynvim/msgpack_rpc/session.py", line 104, in request
    raise self.error_wrapper(err)
pynvim.api.common.NvimError: Vim:E158: Invalid buffer name: /Users/ronan/dotfiles/vim/.vim/plugged/vimspector/support/test/python/simple_python/main.py

and clicking option 3 gives,

Error detected while processing function vimspector#Continue[1]..provider#python3#Call:
line   18:
Error invoking 'python_execute' on channel 3 (python3-script-host):
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/ronan/dotfiles/vim/.vim/plugged/vimspector/python3/vimspector/debug_session.py", line 374, in Continue
    self.Start()
  File "/Users/ronan/dotfiles/vim/.vim/plugged/vimspector/python3/vimspector/debug_session.py", line 195, in Start
    utils.ParseVariables( adapter.get( 'variables', {} ),
AttributeError: 'NoneType' object has no attribute 'get'

The first and third option to not kick off the debugger, i.e. split the tab into its windows.

Next I tried to run a custom minimal vimrc which consisted of the following.

let g:python_host_prog=expand( '$HOME/.pyenv/versions/2.7.15/bin/python2' )
let g:python3_host_prog=expand( '$HOME/.pyenv/versions/3.7.2/bin/python3' )

let s:vimspector_path = expand( '~/.vim/plugged/vimspector' ) " change this
let g:vimspector_enable_mappings = 'HUMAN'
exe 'source ' . s:vimspector_path . '/tests/vimrc'

I ensured the the python providers were all setup correctly tthrough :checkhealth and this had an indentical result to the result mentioned previously.

@puremourning
Copy link
Owner

AttributeError: 'NoneType' object has no attribute 'get'

This is expected, it's because the legacy adapter isn't installed. I just pushed a quick change to make this a proper error message (as it happens regularly enough).

pynvim.api.common.NvimError: Vim:E158: Invalid buffer name: /Users/ronan/dotfiles/vim/.vim/plugged/vimspector/support/test/python/simple_python/main.py

I was able to repro this just now. I can't repro in Vim.

I'll look into it, but neovim is a constant pain in my gut, and it's not a priority for me.

@puremourning puremourning changed the title Pythin debugging not working in neovim Vim:E158: Invalid buffer name <name> when starting debugging in neovim Mar 8, 2020
@puremourning
Copy link
Owner

I suspect this regression happened due to c4bedce, though I dont know why that would cause it.

@RonanMacF
Copy link
Author

vim worked flawlessly for me when I tried it, spend a decent amount of time looking up the error but couldnt come to any reasonable conclusion. I will attempt to set it up tomorrow on a linux machine and see if it gives the same error

@RonanMacF
Copy link
Author

Yep similar problem on CentOS Linux using NVIM v0.4.3 from NIX. Understand its not a priority for you though, I will use something else in the meantime! Cheers

@puremourning
Copy link
Owner

I can confirm that c4bedce is the cause of the issue and I'm like I dunno N% sure it's a neovim bug. I'll ask them.

@puremourning
Copy link
Owner

The good people of #neovim think there might be a neovim bug at play.

Björn Linse @bfredl 20:26
Probably a neovim bug. Even if the file gets unloaded, bufload() should reload it.
I'll debug it after getting some proper sleep :]

@RonanMacF
Copy link
Author

Brilliant to hear! Hopefully won't be anything to do on the vimspector side so!

@puremourning
Copy link
Owner

fixed it with @bfredl's help

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 5, 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

No branches or pull requests

2 participants