Module:Error: Difference between revisions
Jump to navigation
Jump to search
PhantomCaleb (talk | contribs) No edit summary |
PhantomCaleb (talk | contribs) No edit summary |
||
Line 11: | Line 11: | ||
end | 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) | function p.printError(message, category) | ||
local errorMessage = message or DEFAULT_ERROR_MESSAGE | local errorMessage = message or DEFAULT_ERROR_MESSAGE | ||
Line 21: | Line 27: | ||
end | end | ||
function p.warn(message, category) | |||
utilsError.warn(message or "") | |||
return string.format("[[%s]]", category or CATEGORY_ERRORS) | |||
end | |||
p.Templates = { | p.Templates = { | ||
Error = { | Error = { | ||
purpose = "This template | 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 = { | params = { | ||
[1] = { | [1] = { | ||
Line 36: | Line 46: | ||
type = "string", | 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 [[:Category:Hidden categories|hidden]].", | desc = "The name of a category to include with the error so that a list of errors can be tracked. This category should be [[:Category:Hidden categories|hidden]].", | ||
default = CATEGORY_ERRORS | default = CATEGORY_ERRORS, | ||
}, | }, | ||
}, | }, | ||
Line 45: | Line 55: | ||
} | } | ||
}, | }, | ||
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 = "wikitext", | |||
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 [[:Category:Hidden categories|hidden]].", | |||
default = CATEGORY_ERRORS | |||
}, | |||
}, | |||
examples = { | |||
{"Invalid argument <code>foo</code>"}, | |||
{"Invalid argument <code>bar</code>", "{{Invalid Arguments}}"}, | |||
{}, | |||
} | |||
} | |||
} | } | ||
return p | return p |
Revision as of 13:37, 15 September 2022
This module provides functions which templates can invoke when they receive invalid input.
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 or DEFAULT_ERROR_MESSAGE
local errorCategory = category or CATEGORY_ERRORS
utilsError.warn(errorMessage)
local err = mw.html.create("strong")
:addClass("error")
:wikitext(errorMessage)
return string.format("[[:%s|%s]][[%s]]", errorMessage, 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 = "wikitext",
desc = "The error message to display. The message will be displayed both in the article itself and as a [[Template:Warn|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 [[:Category:Hidden categories|hidden]].",
default = CATEGORY_ERRORS,
},
},
examples = {
{"This is an error"},
{"Invalid weapon type", "{{Invalid Arguments}}"},
{},
}
},
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 = "wikitext",
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 [[:Category:Hidden categories|hidden]].",
default = CATEGORY_ERRORS
},
},
examples = {
{"Invalid argument <code>foo</code>"},
{"Invalid argument <code>bar</code>", "{{Invalid Arguments}}"},
{},
}
}
}
return p