fix: fixed invalid index referencing in table due to user-specified invalid mapping configuration

This commit is contained in:
Salih Bozkaya 2023-08-19 14:20:10 +03:00
parent d3d9aa251a
commit 96d83ab549
2 changed files with 53 additions and 23 deletions

20
] Normal file
View File

@ -0,0 +1,20 @@
---@type ChadrcConfig
local M = {}
-- Path to overriding theme and highlights files
local highlights = require "custom.highlights"
M.ui = {
theme = "jellybeans",
-- theme_toggle = { "onedark", "one_light" },
hl_override = highlights.override,
hl_add = highlights.add,
}
M.plugins = "custom.plugins"
-- check core.mappings for table structure
M.mappings = require "custom.mappings"
return M

View File

@ -53,6 +53,7 @@ end
M.load_mappings = function(section, mapping_opt) M.load_mappings = function(section, mapping_opt)
vim.schedule(function() vim.schedule(function()
local function sec_section_map_func()
local function set_section_map(section_values) local function set_section_map(section_values)
if section_values.plugin then if section_values.plugin then
return return
@ -76,6 +77,7 @@ M.load_mappings = function(section, mapping_opt)
local mappings = require("core.utils").load_config().mappings local mappings = require("core.utils").load_config().mappings
if type(section) == "string" then if type(section) == "string" then
mappings[section]["plugin"] = nil mappings[section]["plugin"] = nil
mappings = { mappings[section] } mappings = { mappings[section] }
@ -84,7 +86,15 @@ M.load_mappings = function(section, mapping_opt)
for _, sect in pairs(mappings) do for _, sect in pairs(mappings) do
set_section_map(sect) set_section_map(sect)
end end
end) end
local ok, err = pcall(sec_section_map_func)
if ok == false then
local chadrc_path = vim.api.nvim_get_runtime_file("lua/custom/chadrc.lua", false)[1]
error(string.format("check mappings in %s => %s", chadrc_path, err))
end
end
)
end end
M.lazy_load = function(plugin) M.lazy_load = function(plugin)