{"record":{"id":"6acd8dfdd124e2e6","repo":"diegosouzapw/OmniRoute","slug":"backup-file-is-corrupt-could-not-open","errorCode":null,"errorMessage":"Backup file is corrupt: could not open","messagePattern":"Backup file is corrupt: could not open","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/db/backup.ts","lineNumber":396,"sourceCode":"  const backupPath = path.resolve(backupDir, backupId);\n  // Prevent path traversal: resolved path must stay within backupDir\n  if (\n    !backupPath.startsWith(path.resolve(backupDir) + path.sep) &&\n    backupPath !== path.resolve(backupDir)\n  ) {\n    throw new Error(\"Invalid backup ID: path traversal detected\");\n  }\n\n  if (!fs.existsSync(backupPath)) {\n    throw new Error(`Backup not found: ${backupId}`);\n  }\n\n  // Validate backup integrity\n  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()) {","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/lib/db/backup.ts#L378-L414","documentation":"Error \"Backup file is corrupt: could not open\" thrown in diegosouzapw/OmniRoute.","triggerScenarios":"Thrown at src/lib/db/backup.ts:396 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"}