Unknown --db values report a TypeError instead of the intended error
Los mantenedores suelen responder en 7 días
Evaluación
- Dificultad
- 1/5
- Tiempo estimado
- Menos de una hora
- Aptitud para principiantes
- 88/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Tranquilo
- Stack tecnológico
- javascript
- Área
- cli
Línea de trabajo
Comienza en app/config.js, en getDatabaseConfig, especialmente con la validación alrededor de las líneas 208-213, y confirma el comportamiento con el npm test --db=postgres proporcionado o con un comando directo de Node. Verifica que los nombres desconocidos, incluido toString, produzcan el error previsto, mientras que sqlite, mysql, sqlite: y el valor predeterminado sigan resolviéndose normalmente.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- JavaScript
- Estrellas
- 30
- Forks
- 26
- Merge medio
- 6 d 24 min
- PR fusionados (30 d)
- 6
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Sin plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de shift-org/shift-docs
-
validateRideLength accepts any Object.prototype key as a ride lengthPosiblemente ocupada @gangster la tomó hace 72 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
shift-org/shift-docs#1089 ·
Los mantenedores suelen responder en 7 días
-
Favorites page fetches every favorite because getDaily's guard is invertedPosiblemente ocupada @gangster la tomó hace 72 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
shift-org/shift-docs#1087 ·
Los mantenedores suelen responder en 7 días
-
Address npm audit vulnerabilities (nodemailer, multer, express deps)Posiblemente ocupada @gangster la tomó hace 1 día. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
shift-org/shift-docs#1118 · 1 comentario ·
Los mantenedores suelen responder en 7 días
-
Add an endpoint for Biiikes to check whether an email address organizes an eventQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
shift-org/shift-docs#1106 · 1 comentario ·
Los mantenedores suelen responder en 7 días
-
sitemap.xml emits relative <loc> values, so search engines reject itPosiblemente ocupada @dduugg la tomó hace 98 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 68/100
shift-org/shift-docs#1082 ·
Los mantenedores suelen responder en 7 días
Todos los issues de shift-org/shift-docs
Issues similares
-
change request evaluating
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
sindresorhus/eslint-plugin-unicorn#3907 ·
Los mantenedores suelen responder en 1 día
-
Android bug feature/error-tracking react-native team/error-tracking
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
PostHog/posthog-js#5310 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Add Prettier and a format-check CI jobPosiblemente ocupada @ezekielnathaniel070-ai la tomó hoy. Abiertobackend frontend good first issue Stellar Wave
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
OlaGreat/starbound-realms#98 · 1 comentario ·
-
Add AudiobookshelfAbiertoapp request good first issue help wanted self-hosted app
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Secra-Solutions/Conector#15 ·
-
Complexity: See issue making label epic good first issue Issue Making: Level 1 P-Feature: Project Info and Page role: back end/devOps role: front end size: 0.25pt time sensitive
Dificultad 2/5 Menos de una hora Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día