From 2311d9d883eb709ad9979a726a38c5ce1343b63c Mon Sep 17 00:00:00 2001 From: William Boman Date: Sat, 8 Apr 2023 15:09:30 +0200 Subject: feat(registry): pcall require Lua registry packages (#1200) The index table may get out of date if a user updates the plugin version without restarting Neovim, causing the `require()` call to error (note, restarting Neovim after plugin updates is always a good idea). --- lua/mason-registry/sources/lua.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/mason-registry/sources/lua.lua b/lua/mason-registry/sources/lua.lua index e78bda4c..c3e96075 100644 --- a/lua/mason-registry/sources/lua.lua +++ b/lua/mason-registry/sources/lua.lua @@ -1,3 +1,5 @@ +local log = require "mason-core.log" + ---@class LuaRegistrySourceSpec ---@field id string ---@field mod string @@ -20,7 +22,12 @@ end function LuaRegistrySource:get_package(pkg_name) local index = require(self.spec.mod) if index[pkg_name] then - return require(index[pkg_name]) + local ok, mod = pcall(require, index[pkg_name]) + if ok then + return mod + else + log.fmt_warn("Unable to load %s from %s: %s", pkg_name, self, mod) + end end end -- cgit v1.2.3-70-g09d2