I created a helper function called safe_require()
, it’s very simple, basically what is does is make a protected call to the desired module, and if anything goes wrong, an error is thrown with vim.notify()
and further execution is gracefully aborted, code below:
safe_require.lua:
local function safe_require(module_name)
local status_ok, module = pcall(require, module_name)
if not status_ok then
vim.notify("Couldn't load module '" .. module_name .. "'")
do return end
end
return module
end
But, whenever i try to use it on the config
field of packer
plugins, it fails with the following message:
packer.nvim: Error running config for <plugin_name>: [string "..."]:0: attempt to call upvalue '' (a nil value)
Example of how i’m doing it below:
local safe_require = require "config.helpers.safe_require"
local packer = safe_require "packer"
packer.startup(function(use)
use {"windwp/nvim-autopairs", config = function()
-- this file is responsible for bootstrapping `nvim-autopairs`
safe_require "config.plugins.nvim-autopairs"
end}
end)
Any clue of what i might be missing?