jackwener/OpenCLI · error · ArgumentError

`facebook feed --limit must be an integer between 1 and ${MA

Error message

`facebook feed --limit must be an integer between 1 and ${MAX_LIMIT}`

What it means

requireLimit validates the --limit argument for the facebook feed command: it must parse to an integer between 1 and MAX_LIMIT (50). Anything else — non-numeric strings, floats, zero, negatives, or values above 50 — throws ArgumentError. The validated number is returned and used to cap how many feed items are scraped.

Source

Thrown at clis/facebook/feed.js:10

import { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';

const FACEBOOK_HOME = 'https://www.facebook.com/';
const MAX_LIMIT = 50;

function requireLimit(value) {
  const n = Number(value);
  if (!Number.isInteger(n) || n < 1 || n > MAX_LIMIT) {
    throw new ArgumentError(`facebook feed --limit must be an integer between 1 and ${MAX_LIMIT}`);
  }
  return n;
}

function unwrapBrowserResult(value) {
  if (value && typeof value === 'object' && 'data' in value) {
    return value.data;
  }
  return value;
}

function buildFeedExtractScript(limit) {
  return `(() => {
    const limit = ${limit};

    function clean(value) {
      // Strip zero-width / bidi control chars first: Facebook injects them into
      // decoy nodes to poison scrapers. See issue #2089.

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass an integer between 1 and 50, e.g. facebook feed --limit 20.
  2. If you need more than 50 items, paginate by running the command repeatedly instead of raising the limit.
  3. Sanitize/round the value in your script before passing it: Math.min(50, Math.max(1, Math.round(n))).
  4. Check the flag spelling: --limit takes one numeric value with no units or extra characters.

Example fix

// before
const n = Number(userInput);
await feed({ limit: n }); // throws when n is NaN, 2.5, or > 50

// after
const n = Math.min(50, Math.max(1, Math.round(Number(userInput))));
if (Number.isInteger(n)) await feed({ limit: n });
Defensive patterns

Strategy: validation

Validate before calling

function parseLimit(value) {
  const n = Number(value);
  return Number.isInteger(n) && n >= 1 && n <= 50 ? n : null;
}
const limit = parseLimit(rawFlag);
if (limit === null) limit = 20; // default instead of throwing

Type guard

function isValidLimit(v) {
  return typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= 50;
}

Try / catch

try {
  const n = requireLimit(args.limit);
} catch (err) {
  if (err instanceof ArgumentError) {
    console.error('Usage: facebook feed --limit <1-50>');
    process.exitCode = 2;
  } else {
    throw err;
  }
}

Prevention

When it happens

Trigger: Running facebook feed with --limit set to e.g. 'abc' (NaN), 2.5 (non-integer), 0, -1, or 51+ (exceeds MAX_LIMIT=50).

Common situations: Typos like --limit 5o or --limit=; assuming an unlimited/higher cap and passing 100; scripting the flag with a float from a computation; forgetting the flag's valid range entirely.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


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