louislam/uptime-kuma · critical · Error
Invalid db-config.json, type must be a string
Error message
Invalid db-config.json, type must be a string
What it means
Second guard in readDBConfig(): after confirming dbConfig is an object, it requires dbConfig.type to be a string. Throws when the type field is missing, null, a number, or any non-string value. null and undefined both fail typeof === 'string', so a `{}` or `{ "type": null }` file lands here. This is the most common form of db-config corruption because type is the one mandatory field.
Source
Thrown at server/database.js:216
/**
* Read the database config
* @throws {Error} If the config is invalid
* @typedef {string|undefined} envString
* @returns {{type: "sqlite"} | {type:envString, hostname:envString, port:envString, database:envString, username:envString, password:envString, socketPath:envString}} Database config
*/
static readDBConfig() {
let dbConfig;
let dbConfigString = fs.readFileSync(path.join(Database.dataDir, "db-config.json")).toString("utf-8");
dbConfig = JSON.parse(dbConfigString);
if (typeof dbConfig !== "object") {
throw new Error("Invalid db-config.json, it must be an object");
}
if (typeof dbConfig.type !== "string") {
throw new Error("Invalid db-config.json, type must be a string");
}
return dbConfig;
}
/**
* @typedef {string|undefined} envString
* @param {{type: "sqlite"} | {type:envString, hostname:envString, port:envString, database:envString, username:envString, password:envString, socketPath:envString}} dbConfig the database configuration that should be written
* @returns {void}
*/
static writeDBConfig(dbConfig) {
fs.writeFileSync(path.join(Database.dataDir, "db-config.json"), JSON.stringify(dbConfig, null, 4));
}
/**
* Connect to the database
* @param {boolean} testMode Should the connection be started in test mode?
* @param {boolean} autoloadModels Should models be automatically loaded?
* @param {boolean} noLog Should logs not be output?View on GitHub (pinned to 6b5ea01557)
Solutions
- Ensure db-config.json has `"type": "sqlite"` (or "mariadb" / "embedded-mariadb") as a string at the top level.
- For MariaDB the minimal shape is `{ "type": "mariadb", "hostname": "...", "port": 3306, "database": "...", "username": "...", "password": "..." }`.
- Recreate the file via the setup wizard if you are unsure of the exact schema.
- Lint the file: `node -e "const c=require('./data/db-config.json'); console.log(typeof c.type)"` must print 'string'.
Example fix
// before — data/db-config.json
{}
// after
{
"type": "sqlite"
} Defensive patterns
Strategy: type-guard
Validate before calling
const fs = require("fs"); const path = require("path");
function ensureTypeString(dataDir) {
const cfg = JSON.parse(fs.readFileSync(path.join(dataDir, "db-config.json"), "utf-8"));
if (typeof cfg?.type !== "string") {
throw new Error(`db-config.json: expected 'type' to be a string, got ${typeof cfg?.type}`);
}
return cfg;
} Type guard
function hasStringType(v) {
return v !== null && typeof v === "object" && typeof v.type === "string";
} Try / catch
try {
dbConfig = Database.readDBConfig();
} catch (e) {
if (/type must be a string/.test(e.message)) {
// rewrite db-config.json with the correct type field, then retry
}
throw e;
} Prevention
- Always include `"type": "sqlite"|"mariadb"|"embedded-mariadb"` in db-config.json.
- Use the setup wizard to write the file rather than editing by hand.
- After provisioning, assert the type field with a smoke-test script.
When it happens
Trigger: db-config.json exists and is an object but lacks the `type` key (e.g. `{}`); type is set to a non-string; the file was generated by a tool that serialised only connection params and forgot the type discriminator.
Common situations: Custom provisioning scripts that build the config programmatically; manual editing that accidentally deleted the type line; a partial migration that wrote hostname/port but dropped type.
Related errors
- Unknown Database type: ${dbConfig.type}
- Both ${envName} and ${envName}_FILE are set. Please use only
- Failed to read ${envName}_FILE at ${fileValue}: ${err.messag
- Aggregate table migration is already in progress
- Failed to load docker host config
AI-assisted analysis of louislam/uptime-kuma@6b5ea01557 (2026-08-12).
Data as JSON: /api/errors/a1da40e9b1882f1c.
Report an issue: GitHub.