diegosouzapw/OmniRoute · error · Error
Backup file is corrupt: could not open
Error message
Backup file is corrupt: could not open
What it means
Restore-time integrity gate: the backup file exists but the SQLite driver (tryOpenSync, readonly) could not open it, so it is not a readable SQLite database (truncated, empty, or non-database file). Restore is refused before the live database is torn down.
Solutions
- Discard the corrupt file and restore from a different known-good backup
- Re-create a fresh backup if the current data is healthy and no other backup exists
- Check disk health/free space, since truncation during write is a common cause
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at src/lib/db/backup.ts:396 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25).
Data as JSON: /api/errors/6acd8dfdd124e2e6.
Report an issue: GitHub.
Appendix: source
Thrown at src/lib/db/backup.ts:396
const backupPath = path.resolve(backupDir, backupId);
// Prevent path traversal: resolved path must stay within backupDir
if (
!backupPath.startsWith(path.resolve(backupDir) + path.sep) &&
backupPath !== path.resolve(backupDir)
) {
throw new Error("Invalid backup ID: path traversal detected");
}
if (!fs.existsSync(backupPath)) {
throw new Error(`Backup not found: ${backupId}`);
}
// Validate backup integrity
try {
const { tryOpenSync } = await import("@/lib/db/adapters/driverFactory");
const testDb = tryOpenSync(backupPath, { readonly: true });
if (!testDb) {
throw new Error("Backup file is corrupt: could not open");
}
let result: Array<{ integrity_check?: string }>;
try {
result = testDb.pragma("integrity_check") as Array<{ integrity_check?: string }>;
} finally {
testDb.close();
}
if (result[0]?.integrity_check !== "ok") {
throw new Error("Backup integrity check failed");
}
} catch (e: unknown) {
if (e instanceof Error && e.message === "Backup integrity check failed") throw e;
const message = e instanceof Error ? e.message : String(e);
throw new Error(`Backup file is corrupt: ${message}`);
}
// Force pre-restore backup (bypass throttle) and await so the DB is not closed while backup runs
if (!isSqliteAutoBackupDisabled()) {View on GitHub (pinned to a179ffed5b)