Unknown --db values report a TypeError instead of the intended error
メンテナーはふだん 7 日以内に返信
評価
- 難易度
- 1/5
- 見積もり時間
- 1時間未満
- 初心者へのやさしさ
- 88/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 静か
- 技術スタック
- javascript
- 領域
- cli
調査の方向性
app/config.js の getDatabaseConfig から始め、特に 208-213 行付近のガードを確認し、提供されている npm test --db=postgres または直接 Node コマンドで動作を確認してください。toString を含む未知の名前が意図したエラーを生成する一方で、sqlite、mysql、sqlite:、およびデフォルト値が引き続き正常に解決されることを検証してください。
索引モデルが issue の本文から書いたものです。
説明
getDatabaseConfig means to reject an unrecognised database type with a clear message, but the guard is written as !name in config. Operator precedence makes that (!name) in config, so it tests whether the boolean false is a key of the config object. It never is, so the throw is unreachable for every possible input.
Instead of the intended message, an unknown type dies two lines later with an internal type error pointing at the wrong line.
Reproducing
$ npm test --db=postgres
TypeError: config[name] is not a function
npm error code 7
Or directly:
$ npm_config_db=postgres node -e "require('./app/config.js')"
TypeError: config[name] is not a function
at getDatabaseConfig (app/config.js:213:26)
Expected: unknown database type 'postgres' from line 208.
The precedence is easy to confirm in isolation:
name : "postgres"
!name : false
!name in config : false <-- what is evaluated: (false in config)
!(name in config) : true <-- what was meant
Because !name is false for any non-empty string, the guard never fires — not for postgres, not for banana, not for anything.
A second problem with the obvious fix
The minimal correction is !(name in config), but in walks the prototype chain and config is a plain object literal, so inherited keys would still slip through:
$ npm_config_db=toString node -e "require('./app/config.js')"
no error. db config = {"type":"toString","connect":"[object Object]","debug":false}
config.toString(parts) returns the string "[object Object]", which is then handed on as the connection settings and fails somewhere less obvious in db.js.
This needs someone to type --db=toString, so it is a curiosity rather than a risk. But it is the same class of bug as #1089, and the own-property form is no longer to write.
Suggested fix
- if (!name in config) {
+ if (!Object.hasOwn(config, name)) {
throw new Error(`unknown database type '${dbType}'`)
}
With that, every unrecognised type — including toString and constructor — produces Error: unknown database type '<name>', and sqlite, mysql, sqlite:<path> and the no-argument default all continue to resolve as before.
Severity
Low, and developer-facing only: it costs a contributor a few minutes chasing a misleading stack trace after a typo in --db. Filing it because the fix is one line and the diagnosis is not obvious from the symptom.
- 主要言語
- JavaScript
- スター
- 30
- フォーク
- 26
- 平均マージ
- 6日 24分
- マージ済み PR(30日)
- 6
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
shift-org/shift-docs のほかの issue
-
Export links and the webcal feed 404 under npm run dev対応中かも @dduugg が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
shift-org/shift-docs#1121 ·
メンテナーはふだん 7 日以内に返信
-
validateRideLength accepts any Object.prototype key as a ride length対応中かも @gangster が 73 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
shift-org/shift-docs#1089 ·
メンテナーはふだん 7 日以内に返信
-
Favorites page fetches every favorite because getDaily's guard is inverted対応中かも @gangster が 73 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
shift-org/shift-docs#1087 ·
メンテナーはふだん 7 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
shift-org/shift-docs#1126 ·
メンテナーはふだん 7 日以内に返信
-
Address npm audit vulnerabilities (nodemailer, multer, express deps)対応中かも @gangster が 2 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
shift-org/shift-docs#1118 · コメント 1 件 ·
メンテナーはふだん 7 日以内に返信
shift-org/shift-docs の issue をすべて見る
似ている issue
-
bug lsp sev-3
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
Miaotofu01/Study-Mate#206 ·
メンテナーはふだん 1 日以内に返信
-
effort:low model:light plan planner:fable-5-1 test-quality tests
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
bug good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 63/100
zhw2590582/ArtPlayer#1073 ·