louislam/dockge · warning · Error

Invalid db-config.json, type must be a string

Error message

Invalid db-config.json, type must be a string

What it means

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.

Source

Thrown at backend/database.ts:69

        await Database.patch();
    }

    /**
     * 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}} Database config
     */
    static readDBConfig() : DBConfig {
        const dbConfigString = fs.readFileSync(path.join(this.server.config.dataDir, "db-config.json")).toString("utf-8");
        const 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 dbConfig the database configuration that should be written
     * @returns {void}
     */
    static writeDBConfig(dbConfig : DBConfig) {
        fs.writeFileSync(path.join(this.server.config.dataDir, "db-config.json"), JSON.stringify(dbConfig, null, 4));
    }

    /**
     * Connect to the database
     * @param {boolean} autoloadModels Should models be automatically loaded?
     * @param {boolean} noLog Should logs not be output?
     * @returns {Promise<void>}

View on GitHub (pinned to f809ae192b)

Solutions

  1. Add a valid type string to db-config.json, e.g. {"type": "sqlite"}
  2. Delete db-config.json to let connect() regenerate the default
  3. Note: even with a string type, only "sqlite" is currently supported (see error 35)

Example fix

// before (db-config.json)
{"dialect": "sqlite"}
// after
{"type": "sqlite"}
Defensive patterns

Strategy: validation

Validate before calling

const cfg = JSON.parse(fs.readFileSync(dataDir + "/db-config.json", "utf-8"));
if (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" })); }

Type guard

const hasStringType = (v: unknown): v is { type: string } => typeof v === "object" && v !== null && "type" in v && typeof (v as any).type === "string";

Try / catch

try { Database.connect(); } catch (e) { if (String(e.message).includes("type must be a string")) { fixDBConfig(); return Database.connect(); } throw e; }

Prevention

When it happens

Trigger: db-config.json = {} (type key absent); type set to a number/boolean/nested object; file generated by a tool that wrote the wrong schema.

Common situations: 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.

Related errors


AI-assisted analysis of louislam/dockge@f809ae192b (2026-08-31). Data as JSON: /api/errors/3ff6f621cbe50a6d. Report an issue: GitHub.