aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/_editor.lua
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-11-02 10:11:06 +0800
committerGitHub <noreply@github.com>2024-11-02 10:11:06 +0800
commit3688a333544251c887d78e6501eec55f0fb685f8 (patch)
tree746b606179500e2ecb5c4e93cac5b70e2e2e831f /runtime/lua/vim/_editor.lua
parentb25ae5d328fd58bae5052d1ae19bd1d17a991ea8 (diff)
downloadrneovim-3688a333544251c887d78e6501eec55f0fb685f8.tar.gz
rneovim-3688a333544251c887d78e6501eec55f0fb685f8.tar.bz2
rneovim-3688a333544251c887d78e6501eec55f0fb685f8.zip
fix(lua): show stacktrace for error in vim.on_key() callback (#31021)
Diffstat (limited to 'runtime/lua/vim/_editor.lua')
-rw-r--r--runtime/lua/vim/_editor.lua25
1 files changed, 12 insertions, 13 deletions
diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua
index 3167721a70..cbab2a0165 100644
--- a/runtime/lua/vim/_editor.lua
+++ b/runtime/lua/vim/_editor.lua
@@ -701,11 +701,13 @@ end
--- Executes the on_key callbacks.
---@private
function vim._on_key(buf, typed_buf)
- local failed_ns_ids = {}
- local failed_messages = {}
+ local failed = {} ---@type [integer, string][]
local discard = false
for k, v in pairs(on_key_cbs) do
- local ok, rv = pcall(v[1], buf, typed_buf)
+ local fn = v[1]
+ local ok, rv = xpcall(function()
+ return fn(buf, typed_buf)
+ end, debug.traceback)
if ok and rv ~= nil then
if type(rv) == 'string' and #rv == 0 then
discard = true
@@ -718,19 +720,16 @@ function vim._on_key(buf, typed_buf)
end
if not ok then
vim.on_key(nil, k)
- table.insert(failed_ns_ids, k)
- table.insert(failed_messages, rv)
+ table.insert(failed, { k, rv })
end
end
- if failed_ns_ids[1] then
- error(
- string.format(
- "Error executing 'on_key' with ns_ids '%s'\n Messages: %s",
- table.concat(failed_ns_ids, ', '),
- table.concat(failed_messages, '\n')
- )
- )
+ if #failed > 0 then
+ local errmsg = ''
+ for _, v in ipairs(failed) do
+ errmsg = errmsg .. string.format('\nWith ns_id %d: %s', v[1], v[2])
+ end
+ error(errmsg)
end
return discard
end