diegosouzapw/OmniRoute · error · Error

Backup file is corrupt

Error message

Backup file is corrupt: ${message}

What it means

Catch-all wrapper in restoreDbBackup's integrity-validation try block: any error raised while opening or checking the backup (driver open failure, integrity check failure, driver exceptions) is rethrown as 'Backup file is corrupt: <message>' with the underlying reason appended, signaling the restore must not proceed.

Solutions

  1. Read the appended <message> to distinguish open failure from failed PRAGMA integrity_check
  2. Restore from an alternative backup that passes integrity validation
  3. Re-create a backup from the current database if it is healthy
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at src/lib/db/backup.ts:410 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/c7dd3f219f0c3a96. Report an issue: GitHub.

Appendix: source

Thrown at src/lib/db/backup.ts:410

  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()) {
    _lastBackupAt = 0;
    const backupDirForPre = getBackupDir();
    if (SQLITE_FILE && fs.existsSync(SQLITE_FILE)) {
      const stat = fs.statSync(SQLITE_FILE);
      if (stat.size >= 4096) {
        if (!fs.existsSync(backupDirForPre)) fs.mkdirSync(backupDirForPre, { recursive: true });
        const preBackupPath = path.join(
          backupDirForPre,
          `db_${new Date().toISOString().replace(/[:.]/g, "-")}_pre-restore.sqlite`
        );
        const dbForBackup = getDbInstance();
        await dbForBackup.backup(preBackupPath);
        _lastBackupAt = Date.now();
      }

View on GitHub (pinned to a179ffed5b)