{"record":{"id":"c7dd3f219f0c3a96","repo":"diegosouzapw/OmniRoute","slug":"backup-file-is-corrupt-message","errorCode":null,"errorMessage":"Backup file is corrupt: ${message}","messagePattern":"Backup file is corrupt: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/db/backup.ts","lineNumber":410,"sourceCode":"  try {\n    const { tryOpenSync } = await import(\"@/lib/db/adapters/driverFactory\");\n    const testDb = tryOpenSync(backupPath, { readonly: true });\n    if (!testDb) {\n      throw new Error(\"Backup file is corrupt: could not open\");\n    }\n    let result: Array<{ integrity_check?: string }>;\n    try {\n      result = testDb.pragma(\"integrity_check\") as Array<{ integrity_check?: string }>;\n    } finally {\n      testDb.close();\n    }\n    if (result[0]?.integrity_check !== \"ok\") {\n      throw new Error(\"Backup integrity check failed\");\n    }\n  } catch (e: unknown) {\n    if (e instanceof Error && e.message === \"Backup integrity check failed\") throw e;\n    const message = e instanceof Error ? e.message : String(e);\n    throw new Error(`Backup file is corrupt: ${message}`);\n  }\n\n  // Force pre-restore backup (bypass throttle) and await so the DB is not closed while backup runs\n  if (!isSqliteAutoBackupDisabled()) {\n    _lastBackupAt = 0;\n    const backupDirForPre = getBackupDir();\n    if (SQLITE_FILE && fs.existsSync(SQLITE_FILE)) {\n      const stat = fs.statSync(SQLITE_FILE);\n      if (stat.size >= 4096) {\n        if (!fs.existsSync(backupDirForPre)) fs.mkdirSync(backupDirForPre, { recursive: true });\n        const preBackupPath = path.join(\n          backupDirForPre,\n          `db_${new Date().toISOString().replace(/[:.]/g, \"-\")}_pre-restore.sqlite`\n        );\n        const dbForBackup = getDbInstance();\n        await dbForBackup.backup(preBackupPath);\n        _lastBackupAt = Date.now();\n      }","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/lib/db/backup.ts#L392-L428","documentation":"Error \"Backup file is corrupt: ${message}\" thrown in diegosouzapw/OmniRoute.","triggerScenarios":"Thrown at src/lib/db/backup.ts:410 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","schemaVersion":2},"datasetVersion":"2026-08-25T21:54:21.419Z"}