Module:UtilsError

local p = {} local h = {}

local i18n = require("Module:I18n") local s = i18n.getString local utilsTable = require("Module:UtilsTable")

function p.warn(msg) local callStack = debug.traceback("", 3) local output = msg .. "\n\n" for line in string.gmatch(callStack, "\tModule:[^:]*:[^\n]*\n") do		line = string.gsub(line, "\tModule:([^:]*):(.*)", ":::Module:%1:%2") output = output .. line .. "\n" end mw.addWarning(output) end

function p.required(...) local msg = s("msg.required", h.path(...)) p.warn(msg) return s("cat.invalidFunctionArguments") end

function p.empty(value, ...) local msg = s("msg.empty", h.path(...), utilsTable.print(value)) p.warn(msg) return s("cat.invalidFunctionArguments") end

function p.invalid(value, ...) local msg = s("msg.invalid", value, h.path(...)) p.warn(msg) return s("cat.invalidFunctionArguments") end

function p.invalidKey(key, ...) local msg = s("msg.invalidKey", key, h.path(...)) p.warn(msg) return s("cat.invalidFunctionArguments") end

function h.path(...) local pathComponents = {...} local path = pathComponents[1] for _, pathComponent in pairs(utilsTable.tail(pathComponents)) do path = path .. "[" .. utilsTable.print(pathComponent) .. "]"	end return path end

-- Deprecated. Use p.warn function p.logWarning(msg) local caller = ("%s"):format(p.getRootFrameTitle) local msg = ("%s: %s"):format(caller, msg) mw.addWarning(msg) end

function p.logWarnings(messages) for _, msg in ipairs(messages) do		p.logWarning(msg) end end

function p.getRootFrameTitle local frame = mw.getCurrentFrame while frame:getParent do		frame = frame:getParent end return frame:getTitle end

p.INVALID_TEMPLATE_ARGUMENTS = "Category:Pages using invalid template arguments"

function p.printErrorCategories(...) local result = "" for i,v in ipairs(arg) do       result = ("%s"):format(tostring(v)) .. result end return result end

i18n.loadStrings({	en = {		msg = {			empty = " must be non-empty but is  ",			required = "  is required but is  ",			invalid = "Value   is invalid for  ",			invalidKey = "Key   is invalid for  ",		},		cat = {			invalidFunctionArguments = "Category:Pages with invalid function arguments",		},	} })

return p