diff --git a/runtime/lua/nvim/dir.lua b/runtime/lua/nvim/dir.lua index 0b60fe4d00..79145525d2 100644 --- a/runtime/lua/nvim/dir.lua +++ b/runtime/lua/nvim/dir.lua @@ -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 diff --git a/test/functional/plugin/dir_spec.lua b/test/functional/plugin/dir_spec.lua index b71d43a604..1477cc6129 100644 --- a/test/functional/plugin/dir_spec.lua +++ b/test/functional/plugin/dir_spec.lua @@ -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' } })