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

Feature request: show stacktrace when eval produces an error #37

Open
daveyarwood opened this issue Mar 23, 2019 · 5 comments
Open

Feature request: show stacktrace when eval produces an error #37

daveyarwood opened this issue Mar 23, 2019 · 5 comments

Comments

@daveyarwood
Copy link
Contributor

When I evaluate a form that throws an error, e.g. (/ 1 0), I get the following error:

error caught while executing async callback:
NvimError(b'Vim:E5108: Error while calling lua chunk for luaeval(): ...bundle/acid.nvim//lua/acid/middlewares/clipboard.lua:17: Unexpected type',)
Traceback (most recent call last):
  File "/home/dave/.vim/bundle/acid.nvim/rplugin/python3/acid/__init__.py", line 38, in <lambda>
    nvim.async_call(lambda: handler_impl(msg, wc, key))
  File "/home/dave/.vim/bundle/acid.nvim/rplugin/python3/acid/__init__.py", line 21, in impl
    nvim.funcs.luaeval(lua_cmd, msg)
  File "/usr/local/lib/python3.5/dist-packages/pynvim/api/nvim.py", line 299, in call
    return self.request('nvim_call_function', name, args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/pynvim/api/nvim.py", line 182, in request
    res = self._session.request(name, *args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/pynvim/msgpack_rpc/session.py", line 102, in request
    raise self.error_wrapper(err)
pynvim.api.nvim.NvimError: b'Vim:E5108: Error while calling lua chunk for luaeval(): ...bundle/acid.nvim//lua/acid/middlewares/clipboard.lua:17: Unexpected type'

the call was requested at
  File "/usr/lib/python3.5/threading.py", line 882, in _bootstrap
    self._bootstrap_inner()
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "../../.vim/bundle/acid.nvim/rplugin/python3/acid/nrepl/__init__.py", line 68, in run
    callback(incoming, self, key)
  File "/home/dave/.vim/bundle/acid.nvim/rplugin/python3/acid/__init__.py", line 38, in handler
    nvim.async_call(lambda: handler_impl(msg, wc, key))

Then I see the following written to the virtualtext:

(/ 1 0) ;; => ^[[1;31mjava.lang.ArithmeticException^[[m: ^[[3mDivide by zero^[[m\n

Some ideas:

  • It might be nice to strip out the ANSI color codes in the virtualtext so that the message is easier to read.

  • It would be really great if the stacktrace were easily accessible somehow.

    • Maybe there could be an :AcidShowError command that I could run with my cursor over the line that produced the exception?
    • Simple idea: maybe there could be an :AcidShowLastError that would show you *e?
      • I tried running :call AcidInsertEval() and then evaluating *e, but that just inserted nil into my buffer.
hkupty added a commit that referenced this issue Mar 23, 2019
Avoids python stacktrace, makes error readable later
hkupty added a commit that referenced this issue Mar 23, 2019
Avoids python stacktrace, makes error readable later
@hkupty
Copy link
Member

hkupty commented Mar 23, 2019

I added a workaround for this issue.
The correct way to deal with it would be to implement persistent sessions so *e would work.

Right now, I'm accumulating the errors (on whichever command sent to the nrepl) for them to be displayed if you want to.

That also saves us from the python stacktrace if the print middleware writes to neovim error.

To read from the accumulated error, one must run the following:

:lua require("acid.middleweares.err).show() "Shows last error
:lua require("acid.middleweares.err).show(2) "Shows (last - 2) error

@daveyarwood
Copy link
Contributor Author

That's a nice idea for a workaround!

It doesn't seem to be working for me, though. When I evaluate (/ 1 0), I still see a python stacktrace:

error caught while executing async callback:
NvimError(b'Vim:E5108: Error while calling lua chunk for luaeval(): ...bundle/acid.nvim//lua/acid/middlewares/clipboard.lua:17: Unexpected type',)
Traceback (most recent call last):
  File "/home/dave/.vim/bundle/acid.nvim/rplugin/python3/acid/__init__.py", line 38, in <lambda>
    nvim.async_call(lambda: handler_impl(msg, wc, key))
  File "/home/dave/.vim/bundle/acid.nvim/rplugin/python3/acid/__init__.py", line 21, in impl
    nvim.funcs.luaeval(lua_cmd, msg)
  File "/usr/local/lib/python3.5/dist-packages/pynvim/api/nvim.py", line 299, in call
    return self.request('nvim_call_function', name, args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/pynvim/api/nvim.py", line 182, in request
    res = self._session.request(name, *args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/pynvim/msgpack_rpc/session.py", line 102, in request
    raise self.error_wrapper(err)
pynvim.api.nvim.NvimError: b'Vim:E5108: Error while calling lua chunk for luaeval(): ...bundle/acid.nvim//lua/acid/middlewares/clipboard.lua:17: Unexpected type'

the call was requested at
  File "/usr/lib/python3.5/threading.py", line 882, in _bootstrap
    self._bootstrap_inner()
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "../../.vim/bundle/acid.nvim/rplugin/python3/acid/nrepl/__init__.py", line 68, in run
    callback(incoming, self, key)
  File "/home/dave/.vim/bundle/acid.nvim/rplugin/python3/acid/__init__.py", line 38, in handler
    nvim.async_call(lambda: handler_impl(msg, wc, key))

Then when I run :lua require("acid.middlewares.err").show(), I get this error:

E5105: Error while calling lua chunk: .../.vim/bundle/acid.nvim//lua/acid/middlewares/err.lua:30: Expected lua string

Here is /tmp/acid-log-handler.log from the point where I evaluate (/ 1 0):

2019-03-23 17:40:26,285 - [acid.nvim :DEBUG] - fpath is None
2019-03-23 17:40:26,288 - [acid.nvim :DEBUG] - Hitting cache for ns 'alda.util'
2019-03-23 17:40:26,291 - [acid.session :INFO] - sending data -> {'op': 'eval', 'code': '(/ 1 0)', 'id': '25e71e3e40af4257b82e1a91462589c6', 'ns': 'alda.util'}
2019-03-23 17:40:26,350 - [acid :INFO] - {'status': ['eval-error'], 'root-ex': 'class java.lang.ArithmeticException', 'ex': 'class java.lang.ArithmeticException', 'id': '25e71e3e40af4257b82e1a91462589c6', 'session': '0df82dd2-7cbf-4d67-82d8-606afe90e266'}
2019-03-23 17:40:26,353 - [acid.session :INFO] - stopped watching key 25e71e3e40af4257b82e1a91462589c6-dbc3a0e7572447bc85f6090cfb70d69f-watcher
2019-03-23 17:40:26,356 - [acid :INFO] - {'session': '0df82dd2-7cbf-4d67-82d8-606afe90e266', 'out': '\x1b[1;31mjava.lang.ArithmeticException\x1b[m: \x1b[3mDivide by zero\x1b[m\n', 'id': '25e71e3e40af4257b82e1a91462589c6'}
2019-03-23 17:40:26,362 - [acid :INFO] - {'session': '0df82dd2-7cbf-4d67-82d8-606afe90e266', 'id': '25e71e3e40af4257b82e1a91462589c6', 'status': ['done']}

No additional logs are written when I run the :lua ... command.

@hkupty hkupty mentioned this issue Apr 2, 2019
@hkupty
Copy link
Member

hkupty commented Apr 2, 2019

I'm implementing sessions finally, which allow us to implement an actual wrapper for errors since they now can belong to a session we control.

I'll follow up on that once #55 is merged. Meanwhile, testing and trying are very welcome :)

@hkupty
Copy link
Member

hkupty commented Apr 2, 2019

Btw, just tested and, on #55, one can:

:AcidEval (/ 0 0)
:AcidEval *e
:messages

To get full stacktrace of previous error

@hkupty
Copy link
Member

hkupty commented Apr 9, 2019

Sessions were merged, so I can now proceed with a proper handling of errors/stacktraces.

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

No branches or pull requests

2 participants