louislam/dockge · warning · Error

Invalid db-config.json, it must be an object

Error message

Invalid db-config.json, it must be an object

What it means

Database.readDBConfig reads <dataDir>/db-config.json, JSON.parses it, and requires the result to be an object. If the parsed value is an array, string, number, or null (JSON 'null' is typeof 'object' but here a non-plain object fails downstream; arrays/null pass typeof but the check catches primitives), the method throws 'Invalid db-config.json, it must be an object'. Note connect() catches this and falls back to a default sqlite config, logging a warning.

Source

Thrown at backend/database.ts:65

        await Database.connect();
        log.info("server", "Connected to the database");

        // Patch the database
        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));
    }

    /**

View on GitHub (pinned to f809ae192b)

Solutions

  1. Restore db-config.json to an object: {"type": "sqlite"}
  2. Delete the file and let Dockge regenerate the default sqlite config on next start
  3. Validate the JSON structure: typeof JSON.parse(content) === 'object' && !Array.isArray(...) before replacing it

Example fix

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

Strategy: validation

Validate before calling

const fs = require("fs");
const raw = JSON.parse(fs.readFileSync(dataDir + "/db-config.json", "utf-8"));
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) { fs.writeFileSync(dataDir + "/db-config.json", JSON.stringify({ type: "sqlite" })); }

Type guard

function isDBConfig(v: unknown): v is { type: string } { return typeof v === "object" && v !== null && !Array.isArray(v) && typeof (v as any).type === "string"; }

Try / catch

try { Database.connect(); } catch (e) { if (String(e.message).includes("db-config.json")) { /* reset config to {type:'sqlite'} and retry */ } else { throw e; } }

Prevention

When it happens

Trigger: db-config.json contains 'null', a JSON array like [], a quoted string, or any primitive instead of an object like {"type":"sqlite"}.

Common situations: Hand-edited or corrupted config file; empty file truncated by a crash (JSON.parse would throw first, caught by connect); a migration/backup tool overwrote the file; docker volume mounting a wrong file.

Related errors


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