Skip to content

Commit

Permalink
feat(client): show stacktrace information when adapter fails (nvim-ne…
Browse files Browse the repository at this point in the history
…otest#397)

Problem: Warning messages via `vim.notify` do not retain stack trace,
which makes errors or bugs happened on the adapters' side difficult
to troubleshoot. E.g.:

```
    neotest-python: vim/_editor.lua:0: E5560: Vimscript function must not be called in a lua loop callback
```

Solution: Use `xpcall`, instead of `pcall` to access the stacktrace
information, and use it when showing warning (error) messages. E.g.:
  • Loading branch information
wookayin authored Apr 28, 2024
1 parent bd2903e commit 658131e
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions lua/neotest/client/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,17 @@ function neotest.Client:run_tree(tree, args)
return
end
self._state:update_running(adapter_id, root.id, pos_ids)
local success, all_results = pcall(
self._runner.run_tree,
self._runner,
tree,
args,
adapter_id,
adapter,
function(results)
local errmsg = ""
local success, all_results = xpcall(function()
return self._runner.run_tree(self._runner, tree, args, adapter_id, adapter, function(results)
self._state:update_results(adapter_id, results, true)
end
)
end)
end, function(err)
errmsg = debug.traceback(err, 1)
end)

if not success then
lib.notify(("%s: %s"):format(adapter.name, all_results), "warn")
lib.notify(("%s: %s"):format(adapter.name, errmsg), "warn")
all_results = {}
for _, pos in tree:iter() do
all_results[pos.id] = { status = "skipped" }
Expand Down

0 comments on commit 658131e

Please sign in to comment.