{"record":{"id":"42b746ff7f9e1fe8","repo":"diegosouzapw/OmniRoute","slug":"backup-not-found-backupid","errorCode":null,"errorMessage":"Backup not found: ${backupId}","messagePattern":"Backup not found: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/db/backup.ts","lineNumber":388,"sourceCode":"    !backupId.startsWith(\"db_\") ||\n    !backupId.endsWith(\".sqlite\") ||\n    backupId.includes(path.sep) ||\n    backupId.includes(\"/\")\n  ) {\n    throw new Error(\"Invalid backup ID\");\n  }\n\n  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    }","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/lib/db/backup.ts#L370-L406","documentation":"restoreDbBackup validated the backup ID format and traversal safety, but no file exists at the resolved path inside the backup directory — the requested backup was never created, was deleted by retention/cleanup, or the ID is stale.","triggerScenarios":"Thrown at src/lib/db/backup.ts:388 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["List available backups (e.g. via the backup listing API) and pick an existing db_<timestamp>_<reason>.sqlite ID","Re-create a fresh backup before attempting restore if none exists","Refresh any cached/stored backup IDs that may have been pruned by cleanup policies"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}