From 6f3c0da512efdd3d0b3437710d0e031e9dcd1d55 Mon Sep 17 00:00:00 2001 From: Chrono Date: Fri, 29 Mar 2024 09:27:02 +0800 Subject: [PATCH] style(tools/module): improve code style for readability (#12798) --- kong/tools/module.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/kong/tools/module.lua b/kong/tools/module.lua index b41c8d038ee..3f44ba561b0 100644 --- a/kong/tools/module.lua +++ b/kong/tools/module.lua @@ -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