Module:Protect

    From Nonbinary Wiki
    Revision as of 15:21, 19 August 2018 by wikipedia>Petr Matas (Tweak errFormat behavior)

    Documentation for this module may be created at Module:Protect/doc

    local function processResult(errFormat, success, ...)
    	if not success then
    		return string.format(errFormat, tostring(... or '(no message)'))
    	end
    	return ...
    end
    
    local function protect(func, errFormat, raw)
    	errFormat = errFormat or 'Error: %s'
    	if not raw then
    		errFormat = '<strong class="error">' .. errFormat .. '</strong>'
    	end
    	
    	return function (...)
    		return processResult(errFormat, pcall(func, ...))
    	end
    end
    
    return protect