This is the ThingsDB documentation for version v0, click here for the latest version!
Raises a type_err() if the specified expression evaluates to false.
This function does not generate an event.
assert(expression, type(s) [, error_msg])
| Argument | Type | Description |
|---|---|---|
| expression | any (required) | The result of this expression will be type tested. |
| type(s) | str/list (required) | Type name or list with type names to check. |
| error_msg | str (optional) | Custom error message. |
Returns nil if the type of the expression evaluates to true. Otherwise
an type_err() is raised.
This code shows how assert can be used:
type_assert("one", "int");
Raises a type_err() exception
{
"error_msg": "invalid type `str`",
"error_code": -61
}
Or, use a list of type names to check
type_assert(3.14, ["int", "float"]);
Return value in JSON format
null