error

Table of Contents

Function

error — wrap a Zed value as an error

Synopsis

error(val: any) -> error

Description

The error function returns an error version of any value. It wraps the value val to turn it into an error type providing a means to create structured and stacked errors.

Examples

Wrap a record as a structured error:

yield error({message:"bad value", value:this})
{foo:"foo"}
Loading...

Wrap any value as an error:

yield error(this)
1
"foo"
[1,2,3]
Loading...

Test if a value is an error and show its type “kind”:

yield {this,err:is_error(this),kind:kind(this)}
error("exception")
"exception"
Loading...

Comparison of a missing error results in a missing error even if they are the same missing errors so as to not allow field comparisons of two missing fields to succeed:

badfield:=x |> yield badfield==error("missing")
{}
Loading...
Next: every

SuperDB