Zelda Wiki

Want to contribute to this wiki?
Sign up for an account, and get started!

Come join the Zelda Wiki community Discord server!

READ MORE

Zelda Wiki

This module provides functions which templates can invoke when they receive invalid input.

This module exports the following functions.

Warn

{{#invoke:Error|Warn|<message>|<category>}}

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.

Parameters

ParameterStatusDescriptionDefault value
1messageoptionalThe warning message.
2categoryoptionalThe name of the maintenance category to output so that the warning can be tracked.Category:Pages with template errors

Examples

#InputCategories added
1
{{#invoke:Error|Warn|Invalid argument <code>foo</code>}}
2
{{#invoke:Error|Warn|Invalid argument <code>bar</code>|Category:{{Invalid Arguments}}}}
3
{{#invoke:Error|Warn}}

Error

{{#invoke:Error|Error|<message>|<category>}}

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.

Parameters

ParameterStatusDescriptionDefault value
1messageoptionalThe error message.Error
2categoryoptionalThe name of the maintenance category to output alongside the error message so that the error can be tracked.Category:Pages with template errors

Examples

#InputResultCategories added
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.
4
{{#invoke:Error|Error|This is an error}}
Error: This is an error
5
{{#invoke:Error|Error|Invalid weapon type|Category:{{Invalid Arguments}}}}
Error: Invalid weapon type
6
{{#invoke:Error|Error}}
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 = "<p>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.</p><p>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.</p>",
			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:{{Invalid Arguments}}"},
				},
				{
					args = {},
				}
			},
		},
		Warn = {
			desc = "<p>This function [https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#mw.addWarning issues a warning] which only editors can see when previewing the page.</p><p>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.</p>",
			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 <code>foo</code>"},
				},
				{
					args = {"Invalid argument <code>bar</code>|Category:{{Invalid Arguments}}"},
				},
				{
					args = {}
				},
			},
		},
	}
end

return p