k6-docs-hacker

Docs for the k6 JS API generated from types

View on GitHub

Home > k6 > fail

fail() function

Immediately throw an error, aborting the current script iteration.

Signature:

export function fail(err?: string): never;

Parameters

Parameter Type Description
err string Error message that gets printed to stderr.

Returns:

never

Remarks

fail() is a simple convenience wrapper on top of JavaScript’s throw() (because the latter cannot be used as [expr] || throw, which is a convenient way to write k6 test code).