Skip to content

$error function #167

@deepilla

Description

@deepilla

This is a proposal for a new function:

$error(message)

It behaves like XPath's fn:error. Calling $error from an expression causes it to abort with the specified error message. This is useful for validating input data. If, for example, you require certain fields to be present in your JSON, you can check for them upfront and throw a meaningful error if they don't exist.

(
    $assert := function($cond, $msg) {
        $not($cond) ? $error($msg)
    };
    
    $assert(some.value % 2 = 0, "value must be an even number");
    $assert($length(some.other.value) = 3, "value must be a 3 letter acronym");
    $assert(another.value != null, "value cannot be null");

    <-- main expression goes here -->
)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions