diff options
| author | William Boman <william@redwill.se> | 2023-04-08 15:09:30 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-08 13:09:30 +0000 |
| commit | 2311d9d883eb709ad9979a726a38c5ce1343b63c (patch) | |
| tree | a4b20de9c44ca00f22b4bc06681d5aeb8bd65b8a /lua | |
| parent | chore(health): relax unzip requirement (#1199) (diff) | |
| download | mason-2311d9d883eb709ad9979a726a38c5ce1343b63c.tar mason-2311d9d883eb709ad9979a726a38c5ce1343b63c.tar.gz mason-2311d9d883eb709ad9979a726a38c5ce1343b63c.tar.bz2 mason-2311d9d883eb709ad9979a726a38c5ce1343b63c.tar.lz mason-2311d9d883eb709ad9979a726a38c5ce1343b63c.tar.xz mason-2311d9d883eb709ad9979a726a38c5ce1343b63c.tar.zst mason-2311d9d883eb709ad9979a726a38c5ce1343b63c.zip | |
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).
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/mason-registry/sources/lua.lua | 9 |
1 files changed, 8 insertions, 1 deletions
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 |
