Module:Pcall
Appearance
![]() | This module is rated as alpha. It is ready for third-party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
Description | This module attempts to suppress the display of any error |
---|---|
Code source | Pcall |
Status | Alpha |
This module attempts to suppress the display of any error
Documentation
Package items
Other items
main(frame)
(function)- Main function.
- Parameter:
frame
Calling frame. (table) - Returns: Wikitext output.
--- This module attempts to suppress the display of any error
-- @module pcall
-- @alias p
-- @release alpha
local p = {}
--- Main function.
-- @param {table} frame Calling frame.
-- @return Wikitext output.
function main(modToCall, frame)
local args = frame.args
local pckg = frame.args[1]
local fail = frame.args["_fail"] or ''
local includeError = frame.args["_error"]
for k,v in ipairs(frame.args) do
if k - 1 >= 1 then
frame.args[k - 2] = v
end
end
-- get rid of first underscore for arguments "__fail" and "__includeerror"
for k,v in pairs(frame.args) do
if k:find(k, "__fail") or k:find(k, "__error") then
frame.args[k:sub(-k:len() - 1)] = v
frame.args[k] = nil
end
end
local toCall = require("Module:" .. modToCall)[pckg]
local success, result = pcall(toCall, frame)
if success then
return result
else
if includeError then
return result
else
return fail
end
end
end
setmetatable(p, {
__index = function(t, index)
return function(frame)
return main(index, frame)
end
end
})
return p