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

proposal to add 'error' function #27

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

sebastien-rosset
Copy link

@sebastien-rosset sebastien-rosset commented Mar 31, 2023

This PR creates a JEP to address #22.

The proposal is to add a new error function that takes a string expression. If the error function is evaluated, an error is raised with the specified message.

((status == 'up') && `1`) || ((status == 'down') && `0`) || error(join('invalid-value:', [status]))

Copy link
Member

@jamesls jamesls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the proposal. My initial high level feedback is I'd like to see more motivation why this needs to be part of JMESPath. Historically we've stayed away from the schema validation space and you mentioned JSON schema as an alternative. While how heavyweight JSON schema is depends on the specific implementation/library, I'm hesitant for JMESPath to become an alternative (there's a lot more functionality needed to provide the type of validation people might expect).

Additional things that would help in this section:

  • Concrete use cases
  • Other tools that have similar functionality

As always though, I'd love to hear from others what they think.


## Motivation

AFAIK, there is no dedicated function to raise a runtime error within a JMESpath expression.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The motivation section should go into more detail as to why JMESPath expressions need the ability to raise a runtime error. The existing errors are intended for cases where the user has made a mistake in their expression. JMESPath is primarily a language for filtering/extracting/reshaping JSON data, and not really about schema validation. This section should make a convincing case for that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a section with concrete use cases and improved the motivation section.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamesls , does this address your concerns?

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

Successfully merging this pull request may close these issues.

None yet

2 participants