jackwener/OpenCLI · error · ArgumentError

--max-scrolls must be an integer between 0 and 80

Error message

--max-scrolls must be an integer between 0 and 80

What it means

parseMaxScrolls converts the --max-scrolls argument to a number and throws ArgumentError unless it is an integer between 0 and 80 inclusive. It defaults to 30 when the value is undefined/null/empty, so the error only fires for out-of-range or non-integer values. This caps scroll work during thread snapshot collection.

Source

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

const LINKEDIN_DOMAIN = 'www.linkedin.com';

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

function requireLinkedInThreadUrl(value, label) {
  const url = canonicalizeLinkedInThreadUrl(value);
  if (!url) throw new ArgumentError(`${label} must be an exact https://www.linkedin.com/messaging/thread/<id>/ URL`);
  return url;
}

function parseMaxScrolls(value) {
  if (value === undefined || value === null || value === '') return 30;
  const scrolls = Number(value);
  if (!Number.isInteger(scrolls) || scrolls < 0 || scrolls > 80) {
    throw new ArgumentError('--max-scrolls must be an integer between 0 and 80');
  }
  return scrolls;
}

function buildThreadApiDiscoveryScript(maxScrolls) {
  return String.raw`(async () => {
    const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
    const pageText = document.body ? (document.body.innerText || '') : '';
    const authRequired = /\b(sign in|log in|join linkedin)\b/i.test(pageText)
      || /linkedin\.com\/(login|checkpoint|authwall|uas)/i.test(location.href)
      || /captcha|verification required/i.test(pageText);

    const selectors = [
      '.msg-s-message-list',
      '.msg-s-message-list-scrollable',
      '.msg-thread',
      'main [role="main"]',
      'main'

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use an integer from 0 to 80, e.g. --max-scrolls 80 for maximum history.
  2. Omit the flag to use the default of 30.
  3. Replace non-numeric strings ('all') with a number in range.
  4. Clamp in scripts before invoking: Math.min(80, Math.max(0, Math.round(value))).

Example fix

// before
node cli.js thread-snapshot --thread-url "$URL" --max-scrolls 200
// after
node cli.js thread-snapshot --thread-url "$URL" --max-scrolls 80
Defensive patterns

Strategy: validation

Validate before calling

function assertMaxScrolls(v) {
  if (v === undefined || v === null || v === '') return 30;
  const n = Number(v);
  if (!Number.isInteger(n) || n < 0 || n > 80) {
    throw new Error('--max-scrolls must be an integer between 0 and 80');
  }
  return n;
}

Type guard

const maxScrollsOk = (v) => v === undefined || v === null || v === '' ||
  (Number.isInteger(Number(v)) && Number(v) >= 0 && Number(v) <= 80);

Try / catch

try {
  await threadSnapshot({ 'thread-url': url, 'max-scrolls': scrolls });
} catch (e) {
  if (e instanceof ArgumentError && e.message.startsWith('--max-scrolls')) {
    console.error('Invalid --max-scrolls; using 30 (allowed: integer 0..80).');
  } else throw e;
}

Prevention

When it happens

Trigger: Running thread-snapshot with e.g. `--max-scrolls 100` (above 80), `--max-scrolls -1` (below 0), `--max-scrolls 2.5` (non-integer), or `--max-scrolls unlimited` (non-numeric).

Common situations: Users wanting deeper history assuming a higher cap is allowed; scripts interpolating invalid values; mistaking the flag for a boolean and passing a stray token.

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/592f97a384fe889e. Report an issue: GitHub.