Jump to content

Module:Protect

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Petr Matas (talk | contribs) at 15:21, 19 August 2018 (Tweak errFormat behavior). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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