Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style(tools/module): improve code style for readability #12798

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions kong/tools/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ local _M = {}
-- @return success A boolean indicating whether the module was found.
-- @return module The retrieved module, or the error in case of a failure
function _M.load_module_if_exists(module_name)
local status, res = xpcall(function()
return require(module_name)
end, debug.traceback)
local status, res = xpcall(require, debug.traceback, module_name)

if status then
return true, res
end

-- Here we match any character because if a module has a dash '-' in its name, we would need to escape it.
elseif type(res) == "string" and find(res, "module '" .. module_name .. "' not found", nil, true) then
if type(res) == "string" and find(res, "module '" .. module_name .. "' not found", nil, true) then
return false, res
else
error("error loading module '" .. module_name .. "':\n" .. res)
end

error("error loading module '" .. module_name .. "':\n" .. res)
end


Expand Down
Loading