Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. Read the Privacy Policy to learn what information we collect about you and how we use it.
If you log in or create an account, your edits will be attributed to your username, along with other benefits.
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(options, success, ...) | | local function processResult(errFormat, success, ...) |
| if not success then | | if not success then |
| local message = tostring(... or '(no message)') | | return string.format(errFormat, tostring(... or '(no message)')) |
| if options.removeLocation then
| |
| message = string.gsub(message, '^Module:[^:]+:%d+: ', '', 1)
| |
| end
| |
| return string.format(options.errFormat, message)
| |
| end | | end |
| return ... | | return ... |
| end | | end |
|
| |
|
| local function protect(func, errFormat, options) | | local function protect(func, errFormat, raw) |
| if type(errFormat) == 'table' then | | errFormat = errFormat or 'Error: %s' |
| options = options or errFormat | | if not raw then |
| errFormat = nil
| | errFormat = '<strong class="error">' .. errFormat .. '</strong>' |
| end | | end |
| options = mw.clone(options) or {}
| |
| options.errFormat = errFormat or options.errFormat or 'Error: %s'
| |
| if not options.raw then
| |
| options.errFormat = '<strong class="error">' .. options.errFormat .. '</strong>'
| |
| end
| |
| options.removeLocation = options.removeLocation == nil or options.removeLocation
| |
| | | |
| return function (...) | | return function (...) |
| return processResult(options, pcall(func, ...)) | | return processResult(errFormat, pcall(func, ...)) |
| end | | end |
| end | | end |
|
| |
|
| return protect | | return protect |