Module:UtilsError

local p = {}

function p.error(msg, warnMsg) local errorMessage = msg and ("Error: "..msg) or "Error" local page = mw.getCurrentFrame:getParent:getTitle local hoverText = page if warnMsg then if type(warnMsg) == "boolean" then warnMsg = msg or "Error" end warnMsg = p.warn(warnMsg) if warnMsg ~= msg and msg ~= nil then hoverText = warnMsg end end hoverText = string.gsub(hoverText, '"', "&quot;")	hoverText = string.gsub(hoverText, "]", "&#93;")	local err = string.format('%s ', page, hoverText, errorMessage)	return mw.getCurrentFrame:preprocess(err) end

function p.warn(msg, options) local options = options or {} local omitFrames = options.omitFrames or 0 local traceBack = options.traceBack omitFrames = omitFrames or 0 local errorSource local invokeFrame = mw.getCurrentFrame:getParent:getTitle if mw.title.new(invokeFrame).nsText == "Template" then local template ="" .. mw.getCurrentFrame:getParent:getTitle .. "" msg = "Misuse of " .. template .. ": " .. msg traceBack = false end if traceBack ~= false then local trace = "" local callStack = debug.traceback("", 2) for line in string.gmatch(callStack, "\tModule:[^:]*:[^\n]*\n") do			if omitFrames ~= 0 then omitFrames = omitFrames - 1 else line = string.gsub(line, "\tModule:([^:]*):(.*)", ':: Module:%1:%2 ') trace = trace .. line .. "\n" end end mw.addWarning(msg.."\n\n"..trace) else mw.addWarning(msg) end return msg end

p.Schemas = { error = { error = { type = "string", required = true, desc = "Error message to display.", },		warning = { desc = " If, the error message will also be logged as a warning.  If a string, that message will be logged as the warning - this can be used to provide additional error information to editors. The message will also appear when hovering over the error. ", oneOf = { {					type = "string", },				{					type = "boolean", },			},		},	},	warn = { msg = { type = "string", required = true, desc = "Warning message to log above the edit preview area.", },		options = { type = "record", properties = { {					name = "traceBack", type = "boolean", default = true, desc = "If true, prints a stack trace of all module frames. If the invoking frame is a template, the name of the template is appended to the stack trace.", },				{					name = "omitFrames", type = "number", default = 0, desc = "Number of additional frames to omit from the top of the stack trace." },			}		}	} }

p.Documentation = { error = { params = {"error", "warning"}, returns = "An error message in wikitext, linking to the page which invoked the function. This page, which is usually a template, should have documentation on the error.", cases = { resultOnly = true, {				args = {"I AM ERROR"}, },			{				args = {"I AM ERROR 2", true}, },			{				args = {"I AM ERROR", 'warning message with links and  and "quotes"'}, },		}	},	warn = { params = {"msg", "options"}, returns = "Returns nil, but logs the above message, possibly with a stack trace. Preview this page for an example of output.", cases = { {				args = {"I AM ERROR"}, },			{				args = {"I AM ERROR", { omitFrames = 2 }}, },			{				args = {"I AM ERROR", { traceBack = false }}, }		},	}, }

return p