{"record":{"id":"937c8986cb85b0b6","repo":"garrytan/gstack","slug":"keychain-error","errorCode":"keychain_error","errorMessage":"Cannot read Local State for ${browser.name} at ${localStatePath}${reason}","messagePattern":"Cannot read Local State for (.+?) at (.+?)(.+?)","errorType":"exception","errorClass":"CookieImportError","httpStatus":null,"severity":"error","filePath":"browse/src/cookie-import-browser.ts","lineNumber":498,"sourceCode":"  return keys;\n}\n\nasync function getWindowsAesKey(browser: BrowserInfo): Promise<Buffer> {\n  const cacheKey = `win32:${browser.keychainService}`;\n  const cached = keyCache.get(cacheKey);\n  if (cached) return cached;\n\n  const platform = 'win32' as const;\n  const dataDir = getDataDirForPlatform(browser, platform);\n  if (!dataDir) throw new CookieImportError(`No Windows data dir for ${browser.name}`, 'not_installed');\n\n  const localStatePath = path.join(getBaseDir(platform), dataDir, 'Local State');\n  let localState: any;\n  try {\n    localState = JSON.parse(fs.readFileSync(localStatePath, 'utf-8'));\n  } catch (err) {\n    const reason = err instanceof Error ? `: ${err.message}` : '';\n    throw new CookieImportError(\n      `Cannot read Local State for ${browser.name} at ${localStatePath}${reason}`,\n      'keychain_error',\n    );\n  }\n\n  const encryptedKeyB64: string = localState?.os_crypt?.encrypted_key;\n  if (!encryptedKeyB64) {\n    throw new CookieImportError(\n      `No encrypted key in Local State for ${browser.name}`,\n      'keychain_not_found',\n    );\n  }\n\n  // The stored value is base64(b\"DPAPI\" + dpapi_encrypted_bytes) — strip the 5-byte prefix\n  const encryptedKey = Buffer.from(encryptedKeyB64, 'base64').slice(5);\n  const key = await dpapiDecrypt(encryptedKey);\n  keyCache.set(cacheKey, key);\n  return key;","sourceCodeStart":480,"sourceCodeEnd":516,"githubUrl":"https://github.com/garrytan/gstack/blob/94993f74012782fd94416dd44b8314f6363a13a4/browse/src/cookie-import-browser.ts#L480-L516","documentation":"Error \"Cannot read Local State for ${browser.name} at ${localStatePath}${reason}\" thrown in garrytan/gstack.","triggerScenarios":"Thrown at browse/src/cookie-import-browser.ts:498 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"}