Module:Error

local p = {}

local utilsError = require("Module:UtilsError")

local Constants = mw.loadData("Module:Constants/Data")

local DEFAULT_WARN_MESSAGE = "An error occurred" local CATEGORY_ERRORS = "Category:"..Constants.category.templateErrors

function p.Warn(frame) local message, category = frame.args[1], frame.args[2] local errorCategory = category or CATEGORY_ERRORS utilsError.warn(message or DEFAULT_WARN_MESSAGE) return ""..errorCategory.."" end

function p.Error(frame) local message, category = frame.args[1], frame.args[2] local errorCategory = category or CATEGORY_ERRORS return utilsError.error(message, true)..""..errorCategory.."" end

function p.Documentation return { Error = { desc = " This function displays a bolded red error message at the site of the template usage. The error links to the template's page, which should have documentation on the error. Use this function when a template has no sensible fallback option. A full-on error is appropriate for Template:HW Element when no element type is given, for example. Defaulting to any one element would be unwise as it may display false information to the reader. Likewise, displaying nothing at all may confuse the reader. They may think the element simply hasn't been filled yet, or that maybe the weapon has no element. Better that they know an editor made a mistake. The reader might even be motivated to become an editor and fix it themselves. ", frameParams = { [1] = {					name = "message", default = "Error", desc = "The error message.", },				[2] = {					name = "category", default = "Category:Pages with template errors", desc = "The name of the maintenance category to output alongside the error message so that the error can be tracked.", },			},			cases = { resultOnly = true, {					desc = "Note that the error links to Module:Documentation because that's the page invoking the function in these examples. Normally a template page would be linked - see Template:HW Element for example.", args = {"This is an error"}, },				{					args = 	{"Invalid weapon type", "Category:"}, },				{					args = {}, }			},		},		Warn = { desc = " This function issues a warning which only editors can see when previewing the page. Use this function when a template has a sensible fallback in the face of an error and the error needn't be displayed to the user. For example, a template like Template:Color needn't display an error to readers if given an invalid color name. In this case, the text can still be shown without color as a fallback. The template can quietly inform editors without affecting readers. ", frameParams = { [1] = {					name = "message", desc = "The warning message.", },				[2] = {					name = "category", default = "Category:Pages with template errors", desc = "The name of the maintenance category to output so that the warning can be tracked.", },			},			cases = { resultOnly = true, {					args = {"Invalid argument "}, },				{					args = {"Invalid argument |Category:"}, },				{					args = {} },			},		},	} end

return p