Modul:Error

-- @brief--  Error handling.-- -- @author--  [[meta:User:Danny B.]]local Error = {}----------------------------------------Error.commonTypes = {missingValue = {message = "Chybí hodnota",category = "Doplnit hodnotu"},unknownValue = {message = "Neznámá hodnota",category = "Opravit hodnotu"},wrongType = {message = "Špatný formát",category = "Opravit formát"}}-- @brief--  Generate the error message.-- -- @param--  errorData Table-- -- @return--  Wikitextfunction Error.getMessage( errorData )local outputlocal template = mw.text.trim( errorData.template or "" )local text = mw.text.trim( errorData.text or "" )for key, value in pairs( Error.commonTypes ) doif errorData[key] thentext = Error.commonTypes[key].message .. " "if tonumber( errorData[key].paramName ) thentext = text .. errorData[key].paramName .. ".&#160;parametru"elsetext = text .. "parametru „" .. errorData[key].paramName .. "“"endtext = text .. " (" .. errorData[key].paramDesc .. ")."endendif template ~= "" thentemplate = "<nowiki>{{</nowiki>[[Šablona:" .. template .. "|" .. template .. "]]<nowiki>}}</nowiki> — "endif text ~= "" thentext = ": " .. template .. textelseif template ~= "" thentext = ": " .. template .. "Chybné vložení."endoutput = "<strong class=\"error\">CHYBA" .. text .. "</strong>"return outputend-- @brief--  Generate the error category.-- -- @param--  errorData Table-- -- @return--  Wikitextfunction Error.getCategory( errorData )local outputlocal template = mw.text.trim( errorData.template or "" )local category = mw.text.trim( errorData.category or "" )for key, value in pairs( Error.commonTypes ) doif errorData[key] thencategory = Error.commonTypes[key].category .. " "if tonumber( errorData[key].paramName ) thencategory = category .. errorData[key].paramName .. ". parametru"elsecategory = category .. "parametru „" .. errorData[key].paramName .. "“"endendendif category ~= "" thenif template ~= "" thencategory = category .. " v šabloně " .. templateendelsecategory = mw.text.trim( "Opravit chybné volání šablony " .. template )endoutput = "[[Kategorie:Údržba:" .. category .. "]]"return outputend-- @brief--  Generate the error message and error category.-- -- @param--  errorData Table-- -- @return--  Wikitextfunction Error.getText( errorData )local output = ""output = output .. Error.getMessage( errorData )output = output .. "<includeonly>" .. Error.getCategory( errorData ) .. "</includeonly>"return outputend----------------------------------------return Error