Unknown --db values report a TypeError instead of the intended error
Maintainer thường phản hồi trong vòng 7 ngày
Đánh giá
- Độ khó
- 1/5
- Thời gian dự kiến
- Dưới một giờ
- Mức phù hợp với người mới
- 88/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- javascript
- Lĩnh vực
- cli
Hướng nghiên cứu
Bắt đầu trong app/config.js tại getDatabaseConfig, đặc biệt là phần kiểm tra quanh các dòng 208-213, và xác nhận hành vi bằng npm test --db=postgres được cung cấp hoặc lệnh Node trực tiếp. Xác minh rằng các tên không xác định, bao gồm toString, tạo ra lỗi như dự kiến, trong khi sqlite, mysql, sqlite: và giá trị mặc định vẫn được phân giải bình thường.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- JavaScript
- Star
- 30
- Fork
- 26
- Merge trung bình
- 6 ngày 24 phút
- Pull request đã merge (30 ngày)
- 6
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của shift-org/shift-docs
-
Export links and the webcal feed 404 under npm run devCó thể đã có người làm @dduugg đã nhận 5 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
shift-org/shift-docs#1121 ·
Maintainer thường phản hồi trong vòng 7 ngày
-
validateRideLength accepts any Object.prototype key as a ride lengthCó thể đã có người làm @gangster đã nhận 76 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
shift-org/shift-docs#1089 ·
Maintainer thường phản hồi trong vòng 7 ngày
-
Favorites page fetches every favorite because getDaily's guard is invertedCó thể đã có người làm @gangster đã nhận 76 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
shift-org/shift-docs#1087 ·
Maintainer thường phản hồi trong vòng 7 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
shift-org/shift-docs#1126 ·
Maintainer thường phản hồi trong vòng 7 ngày
-
Address npm audit vulnerabilities (nodemailer, multer, express deps)Có thể đã có người làm @gangster đã nhận 5 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
shift-org/shift-docs#1118 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 7 ngày
Tất cả issue của shift-org/shift-docs
Issue tương tự
-
release-followup
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Workspace secrets/constants containing "$" are corrupted when resolved in data source optionsĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area: right sidebar
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
zulip/zulip#40449 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
cleanup
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
uclaacm/membership-portal-ui#409 ·
Maintainer thường phản hồi trong vòng 1 ngày