mirror of
https://github.com/neovim/neovim.git
synced 2026-08-14 11:29:31 +00:00
fix(dir): do not swallow errors raised after the list callback
Problem: An error raised after the list handler ran (e.g. while
rendering) unwinds through the pcall around provider.list()
and is routed back into the now no-op handler: silently
discarded.
Solution: Re-raise the error when the handler has already run.
This commit is contained in:
@@ -268,6 +268,10 @@ function load(buf, name, provider, restore_view, setup, select)
|
||||
|
||||
local ok, call_err = pcall(provider.list, buf, name, on_list) ---@type boolean, any
|
||||
if not ok then
|
||||
if done then
|
||||
-- The handler already ran and would ignore this error: propagate it.
|
||||
error(call_err, 0)
|
||||
end
|
||||
-- Route provider exceptions through the list handler so failures share one cleanup path.
|
||||
on_list(tostring(call_err), nil)
|
||||
end
|
||||
|
||||
@@ -294,6 +294,24 @@ describe('nvim.dir', function()
|
||||
eq({ 'inside.txt' }, lines())
|
||||
end)
|
||||
|
||||
it('does not swallow errors raised after the list callback', function()
|
||||
n.clear({ args = { '--clean' } })
|
||||
|
||||
local err = exec_lua(function()
|
||||
local ok_open, e = pcall(require('nvim.dir').open, 0, 'custom://late-error', {
|
||||
list = function(_, _, cb)
|
||||
cb(nil, { { name = 'file.txt', dir = false } })
|
||||
error('late provider error')
|
||||
end,
|
||||
open = function() end,
|
||||
open_parent = function() end,
|
||||
})
|
||||
return not ok_open and tostring(e) or nil
|
||||
end)
|
||||
ok(err ~= nil and err:find('late provider error', 1, true) ~= nil)
|
||||
eq({ 'file.txt' }, lines())
|
||||
end)
|
||||
|
||||
it('reloads custom listing providers', function()
|
||||
n.clear({ args = { '--clean' } })
|
||||
|
||||
|
||||
Reference in New Issue
Block a user