Unknown --db values report a TypeError instead of the intended error
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 88/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- javascript
- Domain
- cli
Research direction
Start in app/config.js at getDatabaseConfig, especially the guard around lines 208-213, and confirm the behavior with the provided npm test --db=postgres or direct Node command. Verify that unknown names including toString produce the intended error while sqlite, mysql, sqlite:, and the default still resolve normally.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- JavaScript
- Stars
- 30
- Forks
- 25
- Avg merge
- 9m
- Merged PRs (30d)
- 1
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from shift-org/shift-docs
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
shift-org/shift-docs#1089 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
shift-org/shift-docs#1087 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 68/100
shift-org/shift-docs#1082 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 58/100
shift-org/shift-docs#1072 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 58/100
shift-org/shift-docs#1054 ·
All issues in shift-org/shift-docs
Similar issues
-
Difficulty 1/5 1-3 hours Newbie friendliness 72/100
nishantwrp/gsoc-organizations#213 ·
-
Price: 75 USD Priority: 2 (Medium) Time: <1 Hour
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
resend/resend-skills#144 ·
Maintainers usually reply within 1 day
-
[BUG] Traffic chart tests are flaky: the page's startup load overwrites the test's stubbed dataOpenbug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ScottKirvan/Smokey#33 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
openai/codex-plugin-cc#798 ·
Maintainers usually reply within 2 days