{"record":{"id":"edae372f381abde3","repo":"garrytan/gstack","slug":"db-corrupt","errorCode":"db_corrupt","errorMessage":"Cookie database for ${browserName} is corrupt","messagePattern":"Cookie database for (.+?) is corrupt","errorType":"exception","errorClass":"CookieImportError","httpStatus":null,"severity":"error","filePath":"browse/src/cookie-import-browser.ts","lineNumber":402,"sourceCode":"\n// ─── Internal: SQLite Access ────────────────────────────────────\n\nfunction openDb(dbPath: string, browserName: string): Database {\n  // On Windows, Chrome holds exclusive WAL locks even when we open readonly.\n  // The readonly open may \"succeed\" but return empty results because the WAL\n  // (where all actual data lives) can't be replayed. Always use the copy\n  // approach on Windows so we can open read-write and process the WAL.\n  if (process.platform === 'win32') {\n    return openDbFromCopy(dbPath, browserName);\n  }\n  try {\n    return new Database(dbPath, { readonly: true });\n  } catch (err: any) {\n    if (err.message?.includes('SQLITE_BUSY') || err.message?.includes('database is locked')) {\n      return openDbFromCopy(dbPath, browserName);\n    }\n    if (err.message?.includes('SQLITE_CORRUPT') || err.message?.includes('malformed')) {\n      throw new CookieImportError(\n        `Cookie database for ${browserName} is corrupt`,\n        'db_corrupt',\n      );\n    }\n    throw err;\n  }\n}\n\nfunction openDbFromCopy(dbPath: string, browserName: string): Database {\n  // Use os.tmpdir() instead of hardcoded /tmp for cross-platform support (#708)\n  const tmpPath = path.join(os.tmpdir(), `browse-cookies-${browserName.toLowerCase()}-${crypto.randomUUID()}.db`);\n  try {\n    fs.copyFileSync(dbPath, tmpPath);\n    // Also copy WAL and SHM if they exist (for consistent reads)\n    const walPath = dbPath + '-wal';\n    const shmPath = dbPath + '-shm';\n    if (fs.existsSync(walPath)) fs.copyFileSync(walPath, tmpPath + '-wal');\n    if (fs.existsSync(shmPath)) fs.copyFileSync(shmPath, tmpPath + '-shm');","sourceCodeStart":384,"sourceCodeEnd":420,"githubUrl":"https://github.com/garrytan/gstack/blob/94993f74012782fd94416dd44b8314f6363a13a4/browse/src/cookie-import-browser.ts#L384-L420","documentation":"Error \"Cookie database for ${browserName} is corrupt\" thrown in garrytan/gstack.","triggerScenarios":"Thrown at browse/src/cookie-import-browser.ts:402 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":"94993f74012782fd94416dd44b8314f6363a13a4","analyzedAt":"2026-08-12T04:06:23.140Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}