jackwener/OpenCLI · error · CommandExecutionError

LinkedIn messengerMessages GraphQL returned errors.

Error message

LinkedIn messengerMessages GraphQL returned errors.

What it means

Thrown by parseThreadPages when the normalized payload contains a non-empty errors array, meaning LinkedIn's GraphQL endpoint itself reported errors for this messengerMessages query. The library treats a GraphQL error response as fatal for that page rather than emitting a partial thread snapshot.

Source

Thrown at clis/linkedin/thread-snapshot.js:215

}

function parseThreadPages(pages) {
  if (!Array.isArray(pages) || pages.length === 0) {
    throw new CommandExecutionError('LinkedIn messengerMessages API returned no pages.');
  }

  const entities = new Map();
  const apiUrls = [];
  for (const page of pages) {
    if (!page || typeof page !== 'object' || Array.isArray(page) || typeof page.url !== 'string') {
      throw new CommandExecutionError('LinkedIn messengerMessages API returned a malformed page wrapper.');
    }
    const normalized = page.json;
    if (!normalized || typeof normalized !== 'object' || Array.isArray(normalized)) {
      throw new CommandExecutionError('LinkedIn messengerMessages API returned a malformed normalized payload.');
    }
    if (Array.isArray(normalized.errors) && normalized.errors.length > 0) {
      throw new CommandExecutionError('LinkedIn messengerMessages GraphQL returned errors.');
    }
    if (!Array.isArray(normalized.included)) {
      throw new CommandExecutionError('LinkedIn messengerMessages payload is missing the included entity array.');
    }
    const data = normalized.data?.data;
    if (!data || typeof data !== 'object' || Array.isArray(data)) {
      throw new CommandExecutionError('LinkedIn messengerMessages payload is missing normalized data.');
    }
    const container = Object.entries(data).find(([key, value]) => (
      /^messengerMessages/i.test(key)
      && value
      && typeof value === 'object'
      && !Array.isArray(value)
      && (Array.isArray(value['*elements']) || Array.isArray(value.elements))
    ));
    if (!container) {
      throw new CommandExecutionError('LinkedIn messengerMessages payload is missing a message collection.');
    }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Read normalized.errors[0].message to identify the GraphQL failure (unknown query, throttled, access denied).
  2. Reload the thread and rerun so discovery captures the current queryId instead of a stale one.
  3. Retry after a backoff if errors indicate throttling; if 'query not found', update discovery to the freshly issued request URLs.
  4. Re-authenticate if errors indicate access/permission problems.

Example fix

// before: ignoring errors and parsing anyway
const data = json.data?.data;
// after: check GraphQL errors first (as the library does)
if (Array.isArray(json.errors) && json.errors.length > 0) {
  throw new CommandExecutionError('GraphQL errors: ' + json.errors.map((e) => e.message).join('; '));
}
const data = json.data?.data;
Defensive patterns

Strategy: retry

Validate before calling

// Cannot be pre-validated client-side; surface errors before parsing:
if (Array.isArray(json?.errors) && json.errors.length) {
  console.error('GraphQL errors:', json.errors.map((e) => e.message).join('; '));
}

Type guard

function hasGraphQlErrors(json) {
  return Array.isArray(json?.errors) && json.errors.length > 0;
}

Try / catch

try {
  const snapshot = await cli.linkedin.threadSnapshot({ url: threadUrl });
} catch (err) {
  if (err.message.includes('GraphQL returned errors')) {
    // reload to refresh queryId, back off if throttled, retry with exponential backoff
  } else throw err;
}

Prevention

When it happens

Trigger: The replayed fetch succeeded at HTTP level (2xx) but response JSON has normalized.errors set — e.g. GraphQL-level validation errors, throttling, or a stale/unknown queryId no longer accepted server-side.

Common situations: LinkedIn rotated the messengerMessages queryId after a deploy so a cached URL's query is rejected; the session lacks permission for the conversation; the payload exceeded server limits; LinkedIn-side incident returning GraphQL errors while keeping 200 status.

Related errors


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