Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$error function #167

Closed
deepilla opened this issue Mar 2, 2018 · 1 comment
Closed

$error function #167

deepilla opened this issue Mar 2, 2018 · 1 comment

Comments

@deepilla
Copy link
Contributor

deepilla commented Mar 2, 2018

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 -->
)
@andrew-coleman
Copy link
Member

Resolved by #351

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants