Module:CallAssert/doc
Appearance
This template is used in system messages. Changes to it can cause immediate changes to the Wikipedia user interface. To avoid large-scale disruption, any changes should first be tested in this template's /sandbox or /testcases subpage, or in your own user space. The tested changes can then be added in one single edit to this template. Please discuss any changes at the talk page before implementing them. |
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, 'funcName', ...)
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 'funcName(argument_values) failed'
.