jackwener/OpenCLI · warning · EmptyResultError

linkedin post-analytics

Error message

linkedin post-analytics

What it means

This EmptyResultError is thrown by summarize() when the posts argument is a valid array but contains zero posts. It tells the user the analytics ran but there was nothing to aggregate.

Source

Thrown at clis/linkedin/post-analytics.js:18

import { cli, Strategy } from '@jackwener/opencli/registry';
import { CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
import { parseLimit } from './shared.js';
import { collectPosts } from './posts-core.js';

const DEFAULT_LIMIT = 30;
const MAX_LIMIT = 100;

function sum(posts, field) {
  return posts.reduce((total, post) => total + (Number(post[field]) || 0), 0);
}

function summarize(posts) {
  if (!Array.isArray(posts)) {
    throw new CommandExecutionError('LinkedIn post analytics expected an array of posts');
  }
  if (posts.length === 0) {
    throw new EmptyResultError('linkedin post-analytics', 'No posts were available for analytics.');
  }
  const latest = posts[0] || {};
  return {
    posts_analyzed: posts.length,
    total_reactions: sum(posts, 'reactions'),
    total_comments: sum(posts, 'comments'),
    total_reposts: sum(posts, 'reposts'),
    total_impressions: sum(posts, 'impressions'),
    posts_with_media: posts.filter((post) => post.media).length,
    posts_with_urls: posts.filter((post) => post.url).length,
    latest_posted_at: latest.posted_at || '',
    latest_reactions: Number(latest.reactions) || 0,
    latest_comments: Number(latest.comments) || 0,
    latest_reposts: Number(latest.reposts) || 0,
    latest_impressions: Number(latest.impressions) || 0,
    latest_url: latest.url || '',
  };
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Verify the target profile/page actually has visible posts
  2. Check the profile URL is correct and publicly accessible to the signed-in session
  3. Retry while signed in / after scrolling so lazy-loaded posts render
  4. Update the library if LinkedIn changed the posts feed markup causing extraction to miss posts

Example fix

// before
const posts = await scrapePosts(profileWithNoActivity);
// after
if (!posts.length) console.warn('No posts found; skipping analytics');
else summarize(posts);
Defensive patterns

Strategy: try-catch

Validate before calling

const posts = await collectPosts();
if (Array.isArray(posts) && posts.length === 0) {
  console.warn('No posts available for analytics; skipping');
}

Type guard

function hasPosts(v) {
  return Array.isArray(v) && v.length > 0;
}

Try / catch

try {
  const stats = await postAnalytics(posts);
} catch (e) {
  if (e instanceof EmptyResultError || e.name === 'EmptyResultError') {
    return { posts_analyzed: 0, total_reactions: 0, total_comments: 0 };
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling post-analytics on a profile/page whose fetched posts array is empty — no posts exist, or the extraction matched no post elements on the rendered page.

Common situations: Analyzing a brand-new or inactive profile with no posts; posts hidden by privacy settings or feed layout changes; wrong profile URL passed so the scraper landed on a page without a posts list.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


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