From 90952239d24a9c3496bc2ecf7da1624e6e05d37e Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sun, 25 Dec 2022 14:06:41 +0100 Subject: [PATCH] fix(loader): add proper error message when trying to load a plugin that doesn't exist. Fixes #160 --- lua/lazy/core/loader.lua | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lua/lazy/core/loader.lua b/lua/lazy/core/loader.lua index b749da2..3c443d5 100644 --- a/lua/lazy/core/loader.lua +++ b/lua/lazy/core/loader.lua @@ -110,10 +110,20 @@ function M.load(plugins, reason) ---@cast plugins (string|LazyPlugin)[] for _, plugin in pairs(plugins) do - plugin = type(plugin) == "string" and Config.plugins[plugin] or plugin + local try_load = true + + if type(plugin) == "string" then + if not Config.plugins[plugin] then + Util.error("Plugin " .. plugin .. " not found") + try_load = false + else + plugin = Config.plugins[plugin] + end + end + ---@cast plugin LazyPlugin - if not plugin._.loaded then + if try_load and not plugin._.loaded then ---@diagnostic disable-next-line: assign-type-mismatch plugin._.loaded = {} for k, v in pairs(reason) do @@ -137,7 +147,9 @@ function M.load(plugins, reason) end if plugin.dependencies then - M.load(plugin.dependencies, {}) + Util.try(function() + M.load(plugin.dependencies, {}) + end, "Failed to load deps for " .. plugin.name) end M.packadd(plugin.dir)