Module:Error

local utilsError = require("Module:UtilsError")

local p = {}

local DEFAULT_ERROR_MESSAGE = "Error" local CATEGORY_ERRORS = "Category:Pages with template errors"

function p.Error(frame) local args = frame:getParent.args return p.printError(args[1], args[2]) end

function p.Warn(frame) local args = frame:getParent.args return p.warn(args[1], args[2]) end

-- Should maybe be moved to Module:UtilsError function p.printError(message, category) local errorMessage = message and ("Error: " .. message) or DEFAULT_ERROR_MESSAGE local errorCategory = category or CATEGORY_ERRORS utilsError.warn(message or DEFAULT_ERROR_MESSAGE) local err = mw.html.create("strong") :addClass("error") :wikitext(errorMessage) return string.format("%s%s", errorCategory, tostring(err), errorCategory) end

function p.warn(message, category) utilsError.warn(message or "") return string.format("%s", category or CATEGORY_ERRORS) end

p.Templates = { Error = { purpose = "This template displays an error to indicate that a template is being used incorrectly. The error is displayed to readers, unlike Template:Warn.", params = { [1] = {				name = "message", type = "string", desc = "The error message to display. The message will be displayed both in the article itself and as a warning in page edit previews.", default = DEFAULT_ERROR_MESSAGE, },			[2] = {				name = "category", type = "string", desc = "The name of a category to include with the error so that a list of errors can be tracked. This category should be hidden.", default = CATEGORY_ERRORS, },		},		examples = { {"This is an error"}, {"Invalid weapon type", "Category:"}, {},		}	},	Warn = { purpose = "This template issues a warning to indicate that a template is being used incorrectly. Unlike Template:Error, no error is displayed to readers; the error message is only visible to editors in page previews.", params = { [1] = {				name = "message", required = true, type = "string", desc = "The error message to display in page edit previews.", },			[2] = {				name = "category", type = "string", desc = "The name of a category to include with the warning so that a list of warnings can be tracked. This category should be hidden.", default = CATEGORY_ERRORS },		},		examples = { {"Invalid argument "}, {"Invalid argument ", "Category:"}, {},		}	} }

return p