Module:CallAssert/doc

MyWikiBiz, Author Your Legacy — Friday November 15, 2024
< Module:CallAssert
Revision as of 20:53, 15 July 2021 by Zoran (talk | contribs) (Pywikibot 6.4.0)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

This is the documentation page for Module:CallAssert

Template:Module rating Template:Used in system This metamodule provides function callAssert, which simplifies error checking by throwing an error if a given function returns nil or false. This is similar to the built-in function assert, but unlike it, callAssert itself calls the function, whose return value is to be checked. This allows it to include the function name and argument values in the error message.

Usage

local callAssert = require('Module:CallAssert')
local result1, result2, etc = callAssert(func, Template:'funcNameTemplate:', ...)

callAssert calls func(...) and checks if the first returned value evaluates to true. If it does, then it returns all the returned values. If not, it throws an error with a message in the form Template:'funcName(argument_values) failed'.