{"record":{"id":"97d95cbbb0728bf0","repo":"jackwener/OpenCLI","slug":"pixiv-cookie-lookup-returned-malformed-entries","errorCode":null,"errorMessage":"Pixiv cookie lookup returned malformed entries: ${error?.message || error}","messagePattern":"Pixiv cookie lookup returned malformed entries: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/pixiv/bookmark-download.js","lineNumber":200,"sourceCode":"      }\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({\n          rank: plan.row.rank,\n          type,\n          id,\n          title: plan.row.title,\n          download_status: 'success',","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/pixiv/bookmark-download.js#L182-L218","documentation":"Once cookies are confirmed to be an array, formatCookieHeader converts them into a Cookie HTTP header string. This CommandExecutionError is thrown when formatCookieHeader rejects — meaning individual cookie entries are malformed (missing name/value, unexpected fields) even though the overall shape was an array.","triggerScenarios":"formatCookieHeader(rawCookies) throws because one or more cookie objects lack a usable name/value or contain values that cannot be serialized into a header (e.g. null name, non-string value, undefined fields).","commonSituations":"Pixiv session cookies missing required fields after a partial login; a driver returning cookies with extra/odd field types after an upgrade; manually injected or restored cookies that are incomplete; corrupted browser profile cookie store.","solutions":["Log the cookie entries and remove/skip entries missing name or value before formatting","Re-login to Pixiv in the browser to regenerate a clean, complete cookie set","Filter cookies to pixiv.net domains/names the downloader needs (e.g. PHPSESSID) before formatting","Check for driver version changes that alter cookie field names and adjust formatCookieHeader usage"],"exampleFix":"// before: format all entries blindly\ncookies = formatCookieHeader(rawCookies);\n// after: pre-filter unusable entries\nconst usable = rawCookies.filter(c => c && typeof c.name === 'string' && typeof c.value === 'string');\ncookies = formatCookieHeader(usable);","handlingStrategy":"validation","validationCode":"const usable = rawCookies.filter(c => c && typeof c.name === 'string' && typeof c.value === 'string');\nif (usable.length === 0) throw new Error('no usable pixiv cookies; re-login required');\nconst cookies = formatCookieHeader(usable);","typeGuard":"function isWellFormedCookie(c) {\n  return !!c && typeof c.name === 'string' && c.name.length > 0 && typeof c.value === 'string';\n}","tryCatchPattern":"try {\n  cookies = formatCookieHeader(rawCookies);\n} catch (err) {\n  throw new Error(`Pixiv cookie lookup returned malformed entries: ${err.message}`);\n}","preventionTips":["Filter cookie entries for name/value before formatting","Re-login when session cookies come back incomplete","Restrict to needed pixiv.net cookie names (e.g. PHPSESSID)","Diff cookie shapes after upgrading the browser driver"],"tags":["pixiv","cookies","formatting","validation"],"backgroundTag":"malformed-cookie-entries","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}