{"record":{"id":"d18eeebd0077e44f","repo":"jackwener/OpenCLI","slug":"pixiv-cookie-lookup-failed-error-message-er","errorCode":null,"errorMessage":"Pixiv cookie lookup failed: ${error?.message || error}","messagePattern":"Pixiv cookie lookup failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/pixiv/bookmark-download.js","lineNumber":192,"sourceCode":"        plans.push({ ...await prepareIllustPlan(page, row, outputRoot), row });\n      }\n    }\n    const targets = new Set();\n    for (const plan of plans) {\n      const target = plan.kind === 'novel' ? plan.destPath : plan.finalPath;\n      if (targets.has(target)) {\n        throw new CommandExecutionError(`Pixiv bookmark archive contains a duplicate download target: ${target}`);\n      }\n      targets.add(target);\n    }\n\n    let cookies = '';\n    if (type === 'illust') {\n      let rawCookies;\n      try {\n        rawCookies = await page.getCookies({ domain: 'pixiv.net' });\n      } catch (error) {\n        throw new CommandExecutionError(`Pixiv cookie lookup failed: ${error?.message || error}`);\n      }\n      if (!Array.isArray(rawCookies)) {\n        throw new CommandExecutionError('Pixiv cookie lookup returned malformed data');\n      }\n      try {\n        cookies = formatCookieHeader(rawCookies);\n      } catch (error) {\n        throw new CommandExecutionError(`Pixiv cookie lookup returned malformed entries: ${error?.message || error}`);\n      }\n    }\n\n    const committed = [];\n    try {\n      const results = [];\n      for (const plan of plans) {\n        const destination = plan.kind === 'novel'\n          ? commitNovelFile(plan)\n          : await commitIllustPlan(plan, cookies);","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/pixiv/bookmark-download.js#L174-L210","documentation":"For illustration downloads, the command needs the browser session's Pixiv cookies: page.getCookies({ domain: 'pixiv.net' }). If that call rejects, the error is wrapped in this CommandExecutionError. This keeps cookie-retrieval failures distinct from download failures and ensures cleanup/rollback logic sees a typed error.","triggerScenarios":"page.getCookies rejects — the browser page/target has been closed or crashed, the automation session (Playwright/Puppeteer) was disconnected, or the driver throws an internal error while reading the cookie jar.","commonSituations":"Page closed by the user or a timeout before cookie retrieval; browser crashed or was killed; connecting to a remote browser that dropped; calling bookmark-download outside a properly initialized browser context.","solutions":["Re-run the command so a fresh page/browser context is created","Ensure the browser session stays open until after cookie retrieval (don't close the page mid-run)","Verify the Playwright/Puppeteer connection to the browser is alive and the page is on a pixiv.net URL","Re-login to Pixiv in the automation browser if the session is broken","Catch this error and retry once with a new page before failing"],"exampleFix":"// before\nrawCookies = await page.getCookies({ domain: 'pixiv.net' });\n// after: ensure a live page first\nif (page.isClosed?.()) page = await newPixivPage();\nrawCookies = await page.getCookies({ domain: 'pixiv.net' });","handlingStrategy":"retry","validationCode":"if (!page || typeof page.getCookies !== 'function' || page.isClosed?.()) {\n  throw new Error('page is not usable for cookie lookup');\n}","typeGuard":"function canReadCookies(page) {\n  return !!page && typeof page.getCookies === 'function' && !page.isClosed?.();\n}","tryCatchPattern":"let rawCookies;\nfor (let attempt = 0; attempt < 2; attempt++) {\n  try {\n    rawCookies = await page.getCookies({ domain: 'pixiv.net' });\n    break;\n  } catch (err) {\n    if (attempt === 1) throw new Error(`Pixiv cookie lookup failed: ${err.message}`);\n    page = await newPixivPage(); // recreate the page once\n  }\n}","preventionTips":["Keep the browser page open until after cookie retrieval","Recreate the page/context if isClosed() reports true","Confirm the browser process is alive before the download phase","Use fresh, logged-in Pixiv sessions"],"tags":["pixiv","cookies","browser-session","automation"],"backgroundTag":"cookie-retrieval-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}