jackwener/OpenCLI · error · CommandExecutionError

Pixiv cookie lookup returned malformed entries: ${error?.mes

Error message

Pixiv cookie lookup returned malformed entries: ${error?.message || error}

What it means

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.

Source

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

      }
      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({
          rank: plan.row.rank,
          type,
          id,
          title: plan.row.title,
          download_status: 'success',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log the cookie entries and remove/skip entries missing name or value before formatting
  2. Re-login to Pixiv in the browser to regenerate a clean, complete cookie set
  3. Filter cookies to pixiv.net domains/names the downloader needs (e.g. PHPSESSID) before formatting
  4. Check for driver version changes that alter cookie field names and adjust formatCookieHeader usage

Example fix

// before: format all entries blindly
cookies = formatCookieHeader(rawCookies);
// after: pre-filter unusable entries
const usable = rawCookies.filter(c => c && typeof c.name === 'string' && typeof c.value === 'string');
cookies = formatCookieHeader(usable);
Defensive patterns

Strategy: validation

Validate before calling

const usable = rawCookies.filter(c => c && typeof c.name === 'string' && typeof c.value === 'string');
if (usable.length === 0) throw new Error('no usable pixiv cookies; re-login required');
const cookies = formatCookieHeader(usable);

Type guard

function isWellFormedCookie(c) {
  return !!c && typeof c.name === 'string' && c.name.length > 0 && typeof c.value === 'string';
}

Try / catch

try {
  cookies = formatCookieHeader(rawCookies);
} catch (err) {
  throw new Error(`Pixiv cookie lookup returned malformed entries: ${err.message}`);
}

Prevention

When it happens

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

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

Understand the failure class

Related errors


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