{"record":{"id":"27b0121c4b7b8169","repo":"jackwener/OpenCLI","slug":"pixiv-cookie-lookup-returned-malformed-data","errorCode":null,"errorMessage":"Pixiv cookie lookup returned malformed data","messagePattern":"Pixiv cookie lookup returned malformed data","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/pixiv/bookmark-download.js","lineNumber":195,"sourceCode":"    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);\n        committed.push(plan);\n        const id = type === 'novel' ? plan.row.novel_id : plan.row.illust_id;\n        results.push({","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/pixiv/bookmark-download.js#L177-L213","documentation":"After getCookies succeeds, the raw result must be an array of cookie objects. This CommandExecutionError is thrown when the browser driver returns anything else (null, an object, undefined), which would break formatCookieHeader downstream. It guards against driver API changes or unexpected return shapes.","triggerScenarios":"page.getCookies({ domain: 'pixiv.net' }) resolves but its value is not an Array — e.g. a mocked/stubbed page in tests, a driver version whose getCookies returns { cookies: [...] }, or a wrapper that already serialized the result.","commonSituations":"Using a compatibility layer or alternative driver (playwright vs puppeteer) whose cookie API differs; stubbing page.getCookies in tests with a non-array; a version upgrade changing the response shape.","solutions":["Unwrap the correct shape: if the result has a cookies array property, use result.cookies","Pin/align the browser driver version with what this library expects","Fix test stubs so page.getCookies resolves to an array of cookie objects","Add a normalization step mapping the driver's cookie shape to the expected array"],"exampleFix":"// before: assuming array shape\nif (!Array.isArray(rawCookies)) throw new CommandExecutionError('Pixiv cookie lookup returned malformed data');\n// after: normalize driver differences first\nif (rawCookies && Array.isArray(rawCookies.cookies)) rawCookies = rawCookies.cookies;\nif (!Array.isArray(rawCookies)) throw new CommandExecutionError('Pixiv cookie lookup returned malformed data');","handlingStrategy":"type-guard","validationCode":"const raw = await page.getCookies({ domain: 'pixiv.net' });\nconst cookies = Array.isArray(raw) ? raw : Array.isArray(raw?.cookies) ? raw.cookies : null;\nif (!cookies) throw new Error('unexpected getCookies shape');","typeGuard":"function isCookieArray(v) {\n  return Array.isArray(v) && v.every(c => c && typeof c.name === 'string' && typeof c.value === 'string');\n}","tryCatchPattern":"const rawCookies = await page.getCookies({ domain: 'pixiv.net' });\nif (!Array.isArray(rawCookies)) {\n  throw new Error(`Pixiv cookie lookup returned malformed data: ${typeof rawCookies}`);\n}","preventionTips":["Normalize getCookies output across driver versions before use","Keep test stubs shaped like real driver responses","Pin browser automation library versions","Log typeof/keys of unexpected cookie results"],"tags":["pixiv","cookies","shape-validation","driver-compat"],"backgroundTag":"malicious-shape-unexpected-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}