Standardize on error codes for errors express throws

オープン
#6,951 コメント 5 件 リアクション 6 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

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

評価

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

調査の方向性

まず lib/response.js、lib/request.js、lib/utils.js、lib/view.js、lib/application.js に列挙されているエラー箇所を確認し、次に Fastify の文書化されたエラーコードのアプローチと比較します。Express が生成するエラーに対して明示的なコードを割り当て、文書化する範囲を決定します。合意したエラーが安定したコードを公開し、それらのコードが文書化され、関連するテストでカバレッジが確認されれば完了です。

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

説明

6.x ideas

Capturing an idea we've talked about offline.

It would be great to move to using (and documenting) explicit error codes for errors that express itself generates, to allow folks to use them as a contract if they wish. That would free us up from having to worry that someone is matching on error messages themselves, and therefore making error messages part of the semver contract with users.

to jog memories, this came up recently when discussing #6756

We don't have all that many tbh, but here's a table I had claude make w/ sites where we generate an error:

File Line Error Proposed Code
response.js 67 Invalid status code: ... Status code must be an integer. ERR_INVALID_STATUS_CODE
response.js 71 Invalid status code: ... must be greater than 99 and less than 1000. ERR_STATUS_CODE_OUT_OF_RANGE
response.js 386 path argument is required to res.sendFile ERR_MISSING_ARG
response.js 390 path must be a string to res.sendFile ERR_INVALID_ARG_TYPE
response.js 400 path must be absolute or specify root to res.sendFile ERR_INVALID_PATH
response.js 681 Content-Type cannot be set to an Array ERR_INVALID_ARG_TYPE
response.js 755 cookieParser("secret") required for signed cookies ERR_COOKIE_SECRET_REQUIRED
response.js 936 Request aborted ERR_REQUEST_ABORTED
response.js 946 EISDIR, read ERR_EISDIR
request.js 66 name argument is required to req.get ERR_MISSING_ARG
request.js 70 name must be a string to req.get ERR_INVALID_ARG_TYPE
utils.js 148 unknown value for etag function ERR_INVALID_OPTION
utils.js 180 unknown value for query parser function ERR_INVALID_OPTION
view.js 61 No default engine was specified... ERR_NO_VIEW_ENGINE
view.js 84 Module "..." does not provide a view engine. ERR_INVALID_VIEW_ENGINE
application.js 213 app.use() requires a middleware function ERR_INVALID_MIDDLEWARE
application.js 296 callback function required ERR_MISSING_CALLBACK
application.js 562 Failed to lookup view "..." ERR_VIEW_NOT_FOUND

Fastify does this quite well already: https://fastify.dev/docs/latest/Reference/Errors/

主要言語
JavaScript
スター
69.7k
フォーク
25.7k
平均マージ
2日 9時間
マージ済み PR(30日)
4

環境構築

はじめの一歩

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

expressjs/express のほかの issue

expressjs/express の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

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

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