{"record":{"id":"3ff6f621cbe50a6d","repo":"louislam/dockge","slug":"invalid-db-config-json-type-must-be-a-string","errorCode":null,"errorMessage":"Invalid db-config.json, type must be a string","messagePattern":"Invalid db-config\\.json, type must be a string","errorType":"console","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"backend/database.ts","lineNumber":69,"sourceCode":"        await Database.patch();\n    }\n\n    /**\n     * Read the database config\n     * @throws {Error} If the config is invalid\n     * @typedef {string|undefined} envString\n     * @returns {{type: \"sqlite\"} | {type:envString, hostname:envString, port:envString, database:envString, username:envString, password:envString}} Database config\n     */\n    static readDBConfig() : DBConfig {\n        const dbConfigString = fs.readFileSync(path.join(this.server.config.dataDir, \"db-config.json\")).toString(\"utf-8\");\n        const dbConfig = JSON.parse(dbConfigString);\n\n        if (typeof dbConfig !== \"object\") {\n            throw new Error(\"Invalid db-config.json, it must be an object\");\n        }\n\n        if (typeof dbConfig.type !== \"string\") {\n            throw new Error(\"Invalid db-config.json, type must be a string\");\n        }\n        return dbConfig;\n    }\n\n    /**\n     * @typedef {string|undefined} envString\n     * @param dbConfig the database configuration that should be written\n     * @returns {void}\n     */\n    static writeDBConfig(dbConfig : DBConfig) {\n        fs.writeFileSync(path.join(this.server.config.dataDir, \"db-config.json\"), JSON.stringify(dbConfig, null, 4));\n    }\n\n    /**\n     * Connect to the database\n     * @param {boolean} autoloadModels Should models be automatically loaded?\n     * @param {boolean} noLog Should logs not be output?\n     * @returns {Promise<void>}","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/louislam/dockge/blob/f809ae192b571944ad773e9866d3e67064ae8043/backend/database.ts#L51-L87","documentation":"readDBConfig additionally requires the parsed object to have a string `type` field naming the database dialect. If dbConfig.type is missing or not a string (e.g. {\"type\": 123} or {}), it throws 'Invalid db-config.json, type must be a string'. Like the previous check, connect() catches it, warns, and falls back to sqlite defaults.","triggerScenarios":"db-config.json = {} (type key absent); type set to a number/boolean/nested object; file generated by a tool that wrote the wrong schema.","commonSituations":"Manually experimenting with DB settings; partial copy of a config from another app (e.g. uptime-kuma style configs with extra fields but wrong type value); templating engine rendering type as non-string.","solutions":["Add a valid type string to db-config.json, e.g. {\"type\": \"sqlite\"}","Delete db-config.json to let connect() regenerate the default","Note: even with a string type, only \"sqlite\" is currently supported (see error 35)"],"exampleFix":"// before (db-config.json)\n{\"dialect\": \"sqlite\"}\n// after\n{\"type\": \"sqlite\"}","handlingStrategy":"validation","validationCode":"const cfg = JSON.parse(fs.readFileSync(dataDir + \"/db-config.json\", \"utf-8\"));\nif (typeof cfg?.type !== \"string\") { console.error(\"db-config.json missing string 'type'; resetting to sqlite\"); fs.writeFileSync(dataDir + \"/db-config.json\", JSON.stringify({ type: \"sqlite\" })); }","typeGuard":"const hasStringType = (v: unknown): v is { type: string } => typeof v === \"object\" && v !== null && \"type\" in v && typeof (v as any).type === \"string\";","tryCatchPattern":"try { Database.connect(); } catch (e) { if (String(e.message).includes(\"type must be a string\")) { fixDBConfig(); return Database.connect(); } throw e; }","preventionTips":["Always include the exact key `type` with a string value in db-config.json","Copy config schemas from the app's writeDBConfig output, not from other projects","Add a startup smoke test that runs readDBConfig against a sample data dir"],"tags":["database","config","validation","json"],"backgroundTag":"invalid-config-file","analyzedSha":"f809ae192b571944ad773e9866d3e67064ae8043","analyzedAt":"2026-08-31T19:13:50.919Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}