jackwener/OpenCLI · error · ArgumentError

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

Error message

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

What it means

ArgumentError thrown by parseLimit when the --limit value is not an integer between 1 and MAX_LIMIT (10). The function defaults to 5 when the value is absent but rejects any present value that fails Number conversion or range/integer checks.

Source

Thrown at clis/linkedin/people-search.js:24

import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
import { looksLinkedInAuthWall, normalizeWhitespace, unwrapEvaluateResult } from './shared.js';

const LINKEDIN_DOMAIN = 'www.linkedin.com';
const SEARCH_URL_BASE = 'https://www.linkedin.com/search/results/people/';
const MAX_LIMIT = 10;

function requireStringArg(args, key, label = key) {
    const value = normalizeWhitespace(args[key]);
    if (!value) throw new ArgumentError(`${label} is required`);
    return value;
}

function parseLimit(value) {
    if (value === undefined || value === null || value === '') return 5;
    const limit = Number(value);
    if (!Number.isInteger(limit) || limit < 1 || limit > MAX_LIMIT) {
        throw new ArgumentError(`--limit must be an integer between 1 and ${MAX_LIMIT}`);
    }
    return limit;
}

function buildSearchUrl(keywords) {
    return SEARCH_URL_BASE + '?keywords=' + encodeURIComponent(keywords);
}

function normalizeProfileUrl(value) {
    const raw = normalizeWhitespace(value);
    if (!raw) return '';
    try {
        const parsed = new URL(raw);
        const host = parsed.hostname.toLowerCase();
        if (parsed.protocol !== 'https:' || parsed.username || parsed.password || parsed.port) return '';
        if (host !== 'linkedin.com' && host !== 'www.linkedin.com') return '';
        const match = parsed.pathname.match(/^\/in\/([^/?#]+)\/?$/);
        if (!match || !match[1]) return '';

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass an integer between 1 and 10: --limit 10
  2. Clamp the value before invoking: Math.min(10, Math.max(1, parseInt(value, 10)))
  3. Remove commas/units from numeric input before passing
  4. Update scripts that relied on limits above 10 — MAX_LIMIT is hard-capped at 10

Example fix

// before
const limit = userSuppliedLimit; // e.g. 25
await runCli(['people-search', '--keywords', kw, '--limit', limit]);
// after
const limit = Math.min(10, Math.max(1, parseInt(userSuppliedLimit, 10) || 5));
await runCli(['people-search', '--keywords', kw, '--limit', String(limit)]);
Defensive patterns

Strategy: validation

Validate before calling

function validateLimit(value) {
  if (value === undefined || value === null || value === '') return 5;
  const n = Number(value);
  if (!Number.isInteger(n) || n < 1 || n > 10) throw new Error('--limit must be an integer between 1 and 10');
  return n;
}

Type guard

function isValidLimit(v) {
  return v === undefined || v === null || v === '' || (Number.isInteger(Number(v)) && Number(v) >= 1 && Number(v) <= 10);
}

Try / catch

try {
  await runCli(['linkedin', 'people-search', '--keywords', kw, '--limit', limitInput]);
} catch (err) {
  if (String(err.message).startsWith('--limit must be')) {
    console.error('Valid range: 1-10 (default 5)');
    process.exitCode = 2;
  } else throw err;
}

Prevention

When it happens

Trigger: Passing --limit 0, --limit 11, --limit abc, --limit 2.5, or a value like '1e3' that fails the integer/1..MAX_LIMIT check.

Common situations: Typing an out-of-range limit; passing a float or comma-formatted number ('1,000'); an older script using a limit above the library's new cap of 10 after a version change.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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