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 分钟
- 30 天内合并 PR
- 6
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
shift-org/shift-docs 的其他 Issue
-
Export links and the webcal feed 404 under npm run dev可能已有人在做 @dduugg 于 5 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 83/100
shift-org/shift-docs#1121 ·
维护者通常 7 天内回复
-
validateRideLength accepts any Object.prototype key as a ride length可能已有人在做 @gangster 于 76 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
shift-org/shift-docs#1089 ·
维护者通常 7 天内回复
-
Favorites page fetches every favorite because getDaily's guard is inverted可能已有人在做 @gangster 于 76 天前认领。 未关闭
难度 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 于 5 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 35/100
shift-org/shift-docs#1118 · 1 条评论 ·
维护者通常 7 天内回复
查看 shift-org/shift-docs 的全部 Issue
相似的 Issue
-
docs
难度 2/5 1-3 小时 新手友好度 82/100
idean3885/claude-ops-agent#765 ·
维护者通常 1 天内回复
-
check:failed feeds:edit
难度 2/5 1-3 小时 新手友好度 62/100
iptv-org/database#38385 · 1 条评论 ·
维护者通常 6 天内回复
-
release-followup
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
[BUG]: percentTotal not shown as percentage可能已有人在做 @ORITOMI 今天认领。 未关闭bug
难度 1/5 1 小时以内 新手友好度 93/100
维护者通常 2 天内回复