jackwener/OpenCLI · error · CommandExecutionError

facebook feed returned malformed extraction payload

Error message

facebook feed returned malformed extraction payload

What it means

getFacebookFeed validates the extraction payload: it must be a non-null object with an Array rows field. If the page script returned anything else (null, a string, an object without rows), the library throws CommandExecutionError('facebook feed returned malformed extraction payload'). This guards against silent contract drift between the in-page script and the Node-side parser.

Source

Thrown at clis/facebook/feed.js:368

      `Failed to navigate to facebook feed: ${err instanceof Error ? err.message : err}`,
      'Check that facebook.com is reachable and the browser extension is connected.',
    );
  }

  await loadFeedPosts(page, limit);

  let payload;
  try {
    payload = unwrapBrowserResult(await page.evaluate(buildFeedExtractScript(limit)));
  } catch (err) {
    throw new CommandExecutionError(
      `Failed to read facebook feed: ${err instanceof Error ? err.message : err}`,
      'Facebook may not have rendered or the feed markup may have changed.',
    );
  }

  if (!payload || typeof payload !== 'object' || !Array.isArray(payload.rows)) {
    throw new CommandExecutionError('facebook feed returned malformed extraction payload');
  }

  if (payload.status === 'auth') {
    throw new AuthRequiredError('www.facebook.com', 'Open Chrome and log in to Facebook before retrying.');
  }

  if (payload.rows.length > 0) {
    return payload.rows;
  }

  if (payload.status === 'empty') {
    throw new EmptyResultError('facebook feed', 'Facebook did not show any feed posts for this account.');
  }

  const diagnostics = payload.diagnostics || {};
  if (diagnostics.articleCount || diagnostics.actionMenuCount || diagnostics.fallbackActionCount || diagnostics.mainTextLength > 200) {
    throw new CommandExecutionError(
      'facebook feed page rendered but no feed rows could be extracted',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry once; intermittent layouts often resolve on a fresh page load.
  2. Log/inspect the raw evaluate return value to see what shape actually came back.
  3. Update the in-page extraction script so every code path returns { rows: [...] }.
  4. Confirm you are on the desktop facebook.com site, not a mobile/basic redirect.

Example fix

// before
throw new CommandExecutionError('facebook feed returned malformed extraction payload');
// after
if (!payload || typeof payload !== 'object' || !Array.isArray(payload.rows)) {
  throw new CommandExecutionError(`facebook feed returned malformed extraction payload: ${JSON.stringify(payload).slice(0, 200)}`);
}
Defensive patterns

Strategy: type-guard

Type guard

function isFeedPayload(p) {
  return p !== null && typeof p === 'object' && Array.isArray(p.rows);
}

Try / catch

try {
  const rows = await getFacebookFeed(page, { limit: 10 });
} catch (err) {
  if (/malformed extraction payload/.test(err.message)) {
    // retry on a fresh page load; check for alternate mobile/basic layout
  } else throw err;
}

Prevention

When it happens

Trigger: page.evaluate succeeds but its return value is null/undefined or lacks a rows array — e.g. the in-page script hit an unexpected DOM state and returned a fallback value, or unwrapBrowserResult returned a non-object.

Common situations: Facebook serves an alternate layout (mobile/basic/limited experience) the script doesn't recognize; A/B tested markup causes the script's early-return fallback path; extension serialization dropped the object.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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