[Proposal] add `error` function

オープン
#22 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
30/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
compilers

調査の方向性

まず、proposal の error-function の例と、仕様に既に存在するエラー定義を確認してください。その後、関連する jmespath/jmespath.site#115 と #116 の議論を読んでください。新しい関数と発生するエラーがどのように振る舞うべきかを設計として確定し、文書化できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Problem Statement

AFAIK, there is no built-in capability to raise errors from within a JMESpath expression. For example, suppose a JSON document has a status property, and its value is supposed to be up or down. The user wants to map up to 1 and down to 0, which could be done using the following JMESpath expression:

((status == 'up') && `1`) || `0`)

The user may want to detect and raise an error when the input document has a value other than up or down. A workaround is to rely on the fact that some JMESpath expressions are invalid, e.g., to_number('bad') would raise an error.

((status == 'up') && `1`) || ((status == 'down') && `0`) || to_number('bad')

This works but it's very kludgy. In this specific example, one might argue this issue could be validated using a JSON schema, but sometimes there are no JSON schemas.

Proposal

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]))

Additional Information

The spec states errors are raised when problems are encountered during the evaluation process. Currently, the following errors are defined:

  1. invalid-type
  2. unknown-function
  3. invalid-arity

Related: jmespath/jmespath.site#115 , jmespath/jmespath.site#116

主要言語
Python
スター
10
フォーク
3
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

jmespath/jmespath.jep のほかの issue

jmespath/jmespath.jep の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。