Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Operator

assert — test a predicate and produce errors on failure

Synopsis

assert <expr>

Description

The assert operator evaluates the Boolean expression <expr> for each input value, producing its input value if <expr> evaluates to true or a structured error if it does not.

Examples


# spq
assert a > 0
# input
{a:1}
{a:-1}
# expected output
{a:1}
error({message:"assertion failed",expr:"a > 0",on:{a:-1}})