Typecheck return value of chadrc; propagate errors
* Don't blindly assume the only way `require "custom/chadrc.lua" can fail is that the file doesn't exist. * Provide user with a more useful message when return value is wrong
This commit is contained in:
parent
3d78ef3474
commit
6061f9455d
1 changed files with 10 additions and 6 deletions
|
@ -141,12 +141,16 @@ end
|
|||
M.load_config = function()
|
||||
local conf = require "core.default_config"
|
||||
|
||||
local chadrcExists, change = pcall(require, "custom.chadrc")
|
||||
|
||||
-- if chadrc exists , then merge its table into the default config's
|
||||
|
||||
if chadrcExists then
|
||||
conf = vim.tbl_deep_extend("force", conf, change)
|
||||
-- attempt to load and merge a user config
|
||||
local chadrc_exists = vim.fn.filereadable(vim.fn.stdpath "config" .. "/lua/custom/chadrc.lua") == 1
|
||||
if chadrc_exists then
|
||||
-- merge user config if it exists and is a table; otherwise display an error
|
||||
local user_config = require "custom.chadrc"
|
||||
if type(user_config) == 'table' then
|
||||
conf = vim.tbl_deep_extend("force", conf, user_config)
|
||||
else
|
||||
error("User config (chadrc.lua) *must* return a table!")
|
||||
end
|
||||
end
|
||||
|
||||
return conf
|
||||
|
|
Loading…
Reference in a new issue