jackwener/OpenCLI · error · ArgumentError

twitter tweets --limit must be an integer between 1 and ${MA

Error message

twitter tweets --limit must be an integer between 1 and ${MAX_TWEETS_LIMIT}

What it means

normalizeLimit in clis/twitter/tweets.js:87 validates the --limit flag for `opencli twitter tweets`. It defaults to 20 and requires an integer within 1..MAX_TWEETS_LIMIT; anything else (float, 0, negative, above the cap, or a non-number like a string) raises ArgumentError telling the valid range. The cap exists to keep pagination bounded and avoid tripping rate limits.

Source

Thrown at clis/twitter/tweets.js:87

        ) {
            nextCursor = value.value;
        }
        if (Array.isArray(value)) {
            for (const item of value) visit(item);
            return;
        }
        for (const child of Object.values(value)) {
            if (child && typeof child === 'object') visit(child);
        }
    };
    visit(instructions);
    return { tweets, nextCursor };
}

function normalizeLimit(rawLimit) {
    const limit = rawLimit ?? 20;
    if (!Number.isInteger(limit) || limit < 1 || limit > MAX_TWEETS_LIMIT) {
        throw new ArgumentError(
            `twitter tweets --limit must be an integer between 1 and ${MAX_TWEETS_LIMIT}`,
            'Example: opencli twitter tweets @jack --limit 250',
        );
    }
    return limit;
}

function normalizePageDelaySeconds(rawDelay) {
    const delay = rawDelay ?? DEFAULT_PAGE_DELAY_SECONDS;
    if (!Number.isInteger(delay) || delay < 0 || delay > 60) {
        throw new ArgumentError(
            'twitter tweets --page-delay must be an integer between 0 and 60 seconds',
            'Example: opencli twitter tweets @jack --limit 250 --page-delay 2',
        );
    }
    return delay;
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Run with an integer between 1 and the documented MAX_TWEETS_LIMIT (the message states the current max), e.g. --limit 250
  2. Floor/round computed values before passing: Math.floor(Number(raw)) and re-check the range
  3. Check the CLI version for the current cap — MAX_TWEETS_LIMIT may have changed; clamp your default accordingly
  4. In wrapper scripts, validate the flag value before invoking the CLI

Example fix

// before
opencli twitter tweets @jack --limit 12.5
// after
opencli twitter tweets @jack --limit 12
Defensive patterns

Strategy: validation

Validate before calling

const MAX_TWEETS_LIMIT = 250; // match the library's current cap
function assertLimit(v) {
  const n = Number(v);
  if (!Number.isInteger(n) || n < 1 || n > MAX_TWEETS_LIMIT) {
    throw new Error(`--limit must be an integer 1..${MAX_TWEETS_LIMIT}`);
  }
  return n;
}

Type guard

function isValidLimit(v) {
  return Number.isInteger(v) && v >= 1 && v <= 250;
}

Try / catch

import { ArgumentError } from '@jackwener/opencli/errors';
try {
  await run(['twitter', 'tweets', '@jack', '--limit', String(myLimit)]);
} catch (e) {
  if (e instanceof ArgumentError && e.message.includes('--limit')) {
    console.error('Fix --limit: integer between 1 and the documented max.');
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Passing --limit as a non-integer (e.g. --limit 12.5), below 1 (--limit 0 or negative), above MAX_TWEETS_LIMIT, or a non-numeric value that survives flag parsing, when calling `opencli twitter tweets <user>`.

Common situations: Typos like --limit 1000 when the cap is lower; scripting that passes floats ('awk' arithmetic or JS division results); passing a string from a wrapper script; copying an example with a limit larger than the current MAX_TWEETS_LIMIT after the cap was lowered in a newer version.

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/3fd0f4820bc423b9. Report an issue: GitHub.