jackwener/OpenCLI · error · CommandExecutionError

Pixiv cookie lookup returned malformed data

Error message

Pixiv cookie lookup returned malformed data

What it means

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.

Source

Thrown at clis/pixiv/bookmark-download.js:195

    const targets = new Set();
    for (const plan of plans) {
      const target = plan.kind === 'novel' ? plan.destPath : plan.finalPath;
      if (targets.has(target)) {
        throw new CommandExecutionError(`Pixiv bookmark archive contains a duplicate download target: ${target}`);
      }
      targets.add(target);
    }

    let cookies = '';
    if (type === 'illust') {
      let rawCookies;
      try {
        rawCookies = await page.getCookies({ domain: 'pixiv.net' });
      } catch (error) {
        throw new CommandExecutionError(`Pixiv cookie lookup failed: ${error?.message || error}`);
      }
      if (!Array.isArray(rawCookies)) {
        throw new CommandExecutionError('Pixiv cookie lookup returned malformed data');
      }
      try {
        cookies = formatCookieHeader(rawCookies);
      } catch (error) {
        throw new CommandExecutionError(`Pixiv cookie lookup returned malformed entries: ${error?.message || error}`);
      }
    }

    const committed = [];
    try {
      const results = [];
      for (const plan of plans) {
        const destination = plan.kind === 'novel'
          ? commitNovelFile(plan)
          : await commitIllustPlan(plan, cookies);
        committed.push(plan);
        const id = type === 'novel' ? plan.row.novel_id : plan.row.illust_id;
        results.push({

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Unwrap the correct shape: if the result has a cookies array property, use result.cookies
  2. Pin/align the browser driver version with what this library expects
  3. Fix test stubs so page.getCookies resolves to an array of cookie objects
  4. Add a normalization step mapping the driver's cookie shape to the expected array

Example fix

// before: assuming array shape
if (!Array.isArray(rawCookies)) throw new CommandExecutionError('Pixiv cookie lookup returned malformed data');
// after: normalize driver differences first
if (rawCookies && Array.isArray(rawCookies.cookies)) rawCookies = rawCookies.cookies;
if (!Array.isArray(rawCookies)) throw new CommandExecutionError('Pixiv cookie lookup returned malformed data');
Defensive patterns

Strategy: type-guard

Validate before calling

const raw = await page.getCookies({ domain: 'pixiv.net' });
const cookies = Array.isArray(raw) ? raw : Array.isArray(raw?.cookies) ? raw.cookies : null;
if (!cookies) throw new Error('unexpected getCookies shape');

Type guard

function isCookieArray(v) {
  return Array.isArray(v) && v.every(c => c && typeof c.name === 'string' && typeof c.value === 'string');
}

Try / catch

const rawCookies = await page.getCookies({ domain: 'pixiv.net' });
if (!Array.isArray(rawCookies)) {
  throw new Error(`Pixiv cookie lookup returned malformed data: ${typeof rawCookies}`);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/27b0121c4b7b8169. Report an issue: GitHub.