musistudio/claude-code-router · critical
database disk image is malformed: integrity_check returned $
Error message
database disk image is malformed: integrity_check returned ${String(status || "no result")} What it means
assertSqliteDatabaseIntegrity runs PRAGMA integrity_check on the opened database; a status other than "ok" (or no result) means the file is corrupted at the page level. It is used by openSqliteDatabaseWithRecovery to decide whether recovery is needed.
Source
Thrown at packages/core/src/plugins/backend-service.ts:315
return null;
}
if (typeof value === "bigint" || typeof value === "number" || typeof value === "string") {
return value;
}
if (Buffer.isBuffer(value)) {
return value;
}
if (value instanceof Uint8Array) {
return Buffer.from(value);
}
return String(value);
}
function assertSqliteDatabaseIntegrity(database: SqlDatabase): void {
const result = database.exec("PRAGMA integrity_check;");
const status = result[0]?.values?.[0]?.[0];
if (status !== "ok") {
throw new Error(`database disk image is malformed: integrity_check returned ${String(status || "no result")}`);
}
}
function isSqliteOpenCorruptionError(error: unknown): boolean {
const message = formatError(error).toLowerCase();
return message.includes("database disk image is malformed") ||
message.includes("integrity_check") ||
message.includes("file is not a database") ||
message.includes("not an sqlite database");
}
function nextCorruptSqliteBackupPath(dbFile: string): string {
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
const base = `${dbFile}.corrupt-${timestamp}`;
if (!existsSync(base)) {
return base;
}
for (let index = 1; index < 1000; index += 1) {View on GitHub (pinned to 99f24806c6)
Solutions
- Restore the DB from backup or delete it to let the app recreate it
- If the library offers recovery (openSqliteDatabaseWithRecovery), let it rebuild/migrate
- Check disk health and stop syncing the raw DB file with dropbox-like tools
Example fix
// before const db = openDatabase(path); // after const db = openSqliteDatabaseWithRecovery(path); // detects corruption and recovers
Defensive patterns
Strategy: fallback
Validate before calling
null
Type guard
const isSqliteCorruption = (e: unknown): boolean => formatError(e).toLowerCase().includes("database disk image is malformed"); Try / catch
try { db = openDatabase(path); assertSqliteDatabaseIntegrity(db); } catch (e) { if (isSqliteOpenCorruptionError(e)) { await restoreFromBackup(path); db = openDatabase(path); } else throw e; } Prevention
- Back up SQLite files regularly
- Never cloud-sync live DB files
- Use the recovery-aware open path
When it happens
Trigger: Opening a plugin SQLite DB whose file is truncated, has bad pages, or was written by a mismatched SQLite version / interrupted write.
Common situations: Power loss or process kill mid-write, disk-full events, syncing the DB file via cloud storage, or 32/64-bit SQLite library mixing.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- [backend:${ownerId}] SQLite store is corrupt and will be reb
- project_id and path are required to write a Claude Design fi
- [backend:${ownerId}] SQLite store close failed: ${formatErro
AI-assisted analysis of musistudio/claude-code-router@99f24806c6 (2026-08-27).
Data as JSON: /api/errors/bd111a14f914796d.
Report an issue: GitHub.