commit 12689c73d882a29695d3fff4f6f5af642681f0a6
parent 957093da0da9b9875bf75a5e9f7d2305ab427204
Author: Phạm Bình An <111893501+brianhuster@users.noreply.github.com>
Date: Mon, 7 Jul 2025 01:04:03 +0700
fix(vim.pack): add() stops unexpectedly on package load error #34787
Problem:
Error when adding a plugin will make all following plugins not
`:packadd`ed
Solution:
- add() should handle errors from :packadd with pcall()
Co-authored-by: Evgeni Chasnovski <evgeni.chasnovski@gmail.com>
Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
Diffstat:
2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/runtime/lua/vim/pack.lua b/runtime/lua/vim/pack.lua
@@ -625,7 +625,7 @@ local function pack_add(plug, load)
local after_paths = vim.fn.glob(plug.path .. '/after/plugin/**/*.{vim,lua}', false, true)
--- @param path string
vim.tbl_map(function(path)
- pcall(vim.cmd.source, vim.fn.fnameescape(path))
+ vim.cmd.source(vim.fn.fnameescape(path))
end, after_paths)
end
end
@@ -674,23 +674,24 @@ function M.add(specs, opts)
install_list(plugs_to_install)
end
- -- Register and `:packadd` those actually on disk
+ -- Register and load those actually on disk while collecting errors
+ -- Delay showing all errors to have "good" plugins added first
+ local errors = {} --- @type string[]
for _, p in ipairs(plugs) do
if p.info.installed then
- pack_add(p, opts.load)
+ local ok, err = pcall(pack_add, p, opts.load) --[[@as string]]
+ if not ok then
+ p.info.err = err
+ end
end
- end
-
- -- Delay showing all errors to have "good" plugins added first
- local errors = {} --- @type string[]
- for _, p in ipairs(plugs_to_install) do
if p.info.err ~= '' then
errors[#errors + 1] = ('`%s`:\n%s'):format(p.spec.name, p.info.err)
end
end
+
if #errors > 0 then
local error_str = table.concat(errors, '\n\n')
- error(('Errors during installation:\n\n%s'):format(error_str))
+ error(('vim.pack:\n\n%s'):format(error_str))
end
end
diff --git a/test/functional/plugin/pack_spec.lua b/test/functional/plugin/pack_spec.lua
@@ -4,6 +4,11 @@ describe('vim.pack', function()
-- TODO
end)
+ pending('reports errors after loading', function()
+ -- TODO
+ -- Should handle (not let it terminate the function) and report errors from pack_add()
+ end)
+
pending('respects after/', function()
-- TODO
-- Should source 'after/plugin/' directory (even nested files) after