jackwener/OpenCLI · error · ArgumentError

twitter collection --limit must be an integer between 1 and

Error message

twitter collection --limit must be an integer between 1 and ${MAX_USER_TWEETS_LIMIT}

What it means

normalizeCollectionLimit enforces that --limit is an integer within [1, MAX_USER_TWEETS_LIMIT]; non-integers, zero, negatives, or values above the cap throw with the allowed range interpolated. When the flag is omitted, the default MAX_USER_TWEETS_LIMIT is used silently.

Source

Thrown at clis/twitter/collection.js:69

        throw new ArgumentError(
            'twitter collection --until must be an RFC3339 timestamp',
            'Example: opencli twitter collection @jack --until 2026-07-23T00:00:00Z',
        );
    }
    const parsed = new Date(value);
    if (Number.isNaN(parsed.getTime())) {
        throw new ArgumentError(
            'twitter collection --until must be an RFC3339 timestamp',
            'Example: opencli twitter collection @jack --until 2026-07-23T00:00:00Z',
        );
    }
    return parsed;
}

function normalizeCollectionLimit(rawLimit) {
    const limit = rawLimit ?? MAX_USER_TWEETS_LIMIT;
    if (!Number.isInteger(limit) || limit < 1 || limit > MAX_USER_TWEETS_LIMIT) {
        throw new ArgumentError(
            `twitter collection --limit must be an integer between 1 and ${MAX_USER_TWEETS_LIMIT}`,
            'Example: opencli twitter collection @jack --until 2026-07-23T00:00:00Z --limit 250',
        );
    }
    return limit;
}

function normalizeCollectionPageDelaySeconds(rawDelay) {
    const delay = rawDelay ?? DEFAULT_USER_TWEETS_PAGE_DELAY_SECONDS;
    if (!Number.isInteger(delay) || delay < 0 || delay > 60) {
        throw new ArgumentError(
            'twitter collection --page-delay must be an integer between 0 and 60 seconds',
            'Example: opencli twitter collection @jack --until 2026-07-23T00:00:00Z --page-delay 2',
        );
    }
    return delay;
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a plain integer between 1 and MAX_USER_TWEETS_LIMIT (see error message for the cap)
  2. Omit --limit entirely to use the default maximum
  3. Ensure scripts pass numbers, not strings (cast with Number.parseInt first)
  4. Check the CLI docs/help for the current max if you need more tweets — paginate with --until instead

Example fix

// before
--limit 0
// after
--limit 250
Defensive patterns

Strategy: validation

Validate before calling

const MAX_LIMIT = 1000; // check CLI help for actual cap
function validateLimit(n) {
  return Number.isInteger(n) && n >= 1 && n <= MAX_LIMIT;
}
if (!validateLimit(limit)) throw new Error(`--limit must be an integer in [1, ${MAX_LIMIT}]`);

Type guard

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

Try / catch

try {
  await run(['opencli','twitter','collection',handle,'--limit',String(limit)]);
} catch (err) {
  if (String(err.message).startsWith('twitter collection --limit must be an integer')) {
    limit = 250; // fall back to documented example value
  } else throw err;
}

Prevention

When it happens

Trigger: opencli twitter collection --limit 0, --limit -5, --limit 12.5, --limit 100000 (above MAX_USER_TWEETS_LIMIT), or a shell passing '250\n'/unquoted garbage that isn't an integer after ?? defaulting.

Common situations: Assuming the cap is unlimited or a different number; typo'd values like 1ooo; scripts passing string values (Number.isInteger('250') is false); copying a --limit from a different subcommand with a different max.

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