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()
|
M.load_config = function()
|
||||||
local conf = require "core.default_config"
|
local conf = require "core.default_config"
|
||||||
|
|
||||||
local chadrcExists, change = pcall(require, "custom.chadrc")
|
-- 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 its table into the default config's
|
if chadrc_exists then
|
||||||
|
-- merge user config if it exists and is a table; otherwise display an error
|
||||||
if chadrcExists then
|
local user_config = require "custom.chadrc"
|
||||||
conf = vim.tbl_deep_extend("force", conf, change)
|
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
|
end
|
||||||
|
|
||||||
return conf
|
return conf
|
||||||
|
|
Loading…
Reference in a new issue