jackwener/OpenCLI · error · CommandExecutionError

LinkedIn sent invitations returned a malformed extraction pa

Error message

LinkedIn sent invitations returned a malformed extraction payload.

What it means

After auth and warning checks, the command validates the extraction payload shape: it must be a non-null, non-array object whose `rows` property is an array. Anything else means the in-page script did not return the expected structure (serialization problem or unexpected result wrapper) and this CommandExecutionError is thrown.

Source

Thrown at clis/linkedin/sent-invitations.js:102

  description: 'List pending LinkedIn sent invitations for CRM reconciliation',
  domain: LINKEDIN_DOMAIN,
  strategy: Strategy.UI,
  browser: true,
  args: [],
  columns: ['rank', 'name', 'profile_url', 'invited_date_text'],
  func: async (page) => {
    if (!page) throw new CommandExecutionError('Browser session required for linkedin sent-invitations');
    await page.goto(SENT_URL);
    await page.wait(12);
    let result = unwrapEvaluateResult(await page.evaluate(buildSentInvitationsScript()));
    if (result?.authRequired) {
      throw new AuthRequiredError(LINKEDIN_DOMAIN, 'LinkedIn sent invitations requires an active signed-in browser session.');
    }
    if (result?.warning) {
      throw new CommandExecutionError('LinkedIn warning/restriction state visible on sent invitations page.');
    }
    if (!result || typeof result !== 'object' || Array.isArray(result) || !Array.isArray(result.rows)) {
      throw new CommandExecutionError('LinkedIn sent invitations returned a malformed extraction payload.');
    }
    if (result.malformedCount > 0) {
      throw new CommandExecutionError('LinkedIn sent invitations contained a malformed invitation card.');
    }
    const rows = result.rows;
    if (rows.length === 0) {
      if (result.explicitEmpty) {
        throw new EmptyResultError('linkedin sent-invitations', 'No pending sent invitations were found.');
      }
      throw new CommandExecutionError('LinkedIn sent invitation cards were not found; the page structure may have changed.');
    }
    return rows.map((row, index) => ({
      rank: index + 1,
      name: row.name || '',
      profile_url: row.profile_url || '',
      invited_date_text: row.invited_date_text || '',
    }));
  },

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run the command — transient evaluate failures (interrupted script, navigation) usually clear on retry.
  2. Verify the CLI and browser driver versions are compatible; mismatched automation stacks can mangle evaluate return values.
  3. Check whether any customization (unwrapEvaluateResult in shared.js or the extraction script) altered the return contract { rows: [...] }.
  4. Confirm no navigation or page close happens during the 12s wait/evaluate window; keep the tab in the foreground.

Example fix

// before (evaluate returned an array after custom wrapper change)
return cards.map(toRow); // shape break
// after — preserve the documented payload contract
return { url: href, title: document.title, authRequired, warning, explicitEmpty, rows };
Defensive patterns

Strategy: type-guard

Validate before calling

null

Type guard

const isExtractionPayload = (v) =>
  v !== null && typeof v === 'object' && !Array.isArray(v) && Array.isArray(v.rows);

Try / catch

try {
  const rows = await run(['linkedin', 'sent-invitations']);
} catch (e) {
  if (/malformed extraction payload/.test(e.message)) {
    console.error('Extraction returned an unexpected shape — check CLI/driver versions and that the page was not navigated mid-run.');
    process.exit(4);
  }
  throw e;
}

Prevention

When it happens

Trigger: Running `opencli linkedin sent-invitations` where page.evaluate returns null/undefined, a plain array, or an object without a rows array — e.g. unwrapEvaluateResult failed to normalize the value, the evaluate was cut short, or a wrapper returned an unexpected type.

Common situations: Browser automation layer returning serialized values in an unexpected format (version mismatch between CLI and browser driver); a proxy/wrapper around evaluate (unwrapEvaluateResult) failing; page navigation or script error causing evaluate to resolve to undefined; custom modifications to buildSentInvitationsScript returning a different shape.

Understand the failure class

Related errors


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