Skip to main content
Version: v1.11.0

is_error

Function

is_error test if a value is an error

Synopsis

is_error(val: any) -> bool

Description

The is_error function returns true if its argument's type is error. is_error(v) is shortcut for kind(v)=="error",

Examples

A simple value is not an error:

echo 1 | zq -z 'yield is_error(this)' -

=>

false

An error value is an error:

echo "error(1)" | zq -z 'yield is_error(this)' -

=>

true

Convert an error string into a record with an indicator and a message:

echo '"not an error" error("an error")' | zq -z 'yield {err:is_error(this),message:under(this)}' -

=>

{err:false,message:"not an error"}
{err:true,message:"an error"}