Editing Module:Protect
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
local function processResult( | local function wrapMessage(errMessage) | ||
return '<span class="error">' .. errMessage .. '</span>' | |||
end | |||
local defaultFormat = wrapMessage('Error: %s') | |||
local function processResult(errFormat, success, ...) | |||
if not success then | if not success then | ||
return string.format(errFormat, tostring(... or '(no message)')) | |||
end | end | ||
return ... | return ... | ||
end | end | ||
local function protect(func, errFormat, | local function protect(func, errFormat, raw) | ||
if | if not errFormat then | ||
errFormat = defaultFormat | |||
errFormat = | elseif not raw then | ||
errFormat = wrapMessage(errFormat) | |||
end | end | ||
return function (...) | return function (...) | ||
return processResult( | return processResult(errFormat, pcall(func, ...)) | ||
end | end | ||
end | end | ||
return protect | return protect |