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

parseLimit validates the user-supplied --limit option before building the device-follow API URL. If the value is not a string-empty/undefined default (20) and cannot be coerced to an integer between 1 and 200 (MAX_LIMIT), an ArgumentError is thrown. This fail-fast guard prevents sending malformed query params to the Twitter API.

Source

Thrown at clis/twitter/device-follow.js:23

 * to /home; the data is only reachable via the legacy v1.1 REST
 * endpoint `/i/api/2/notifications/device_follow.json`.
 *
 * Endpoint discovery and field-mapping originally proposed by @traddo
 * in issue #1628.
 */
import { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';
import { TWITTER_BEARER_TOKEN, applyTopByEngagement } from './utils.js';
import { describeTwitterApiError } from './shared.js';

const DEVICE_FOLLOW_PATH = '/i/api/2/notifications/device_follow.json';
const MAX_LIMIT = 200;

function parseLimit(value) {
    if (value === undefined || value === null || value === '') return 20;
    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 buildDeviceFollowUrl(count) {
    const params = new URLSearchParams({
        include_profile_interstitial_type: '1',
        include_blocking: '1',
        include_blocked_by: '1',
        include_followed_by: '1',
        include_want_retweets: '1',
        include_mute_edge: '1',
        include_can_dm: '1',
        include_can_media_tag: '1',
        include_ext_has_nft_avatar: '1',
        include_ext_is_blue_verified: '1',
        include_ext_verified_type: '1',
        skip_status: '1',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass an integer between 1 and 200, e.g. --limit 50
  2. Omit --limit entirely to get the default of 20
  3. Trim/validate shell variables before interpolation: --limit "${N//[!0-9]/}"
  4. If you need more than 200 items, paginate the command instead of raising the limit

Example fix

// before
node cli twitter device-follow --limit 500
// after
node cli twitter device-follow --limit 200
Defensive patterns

Strategy: validation

Validate before calling

const n = Number(raw);
if (raw !== undefined && raw !== null && raw !== '' && (!Number.isInteger(n) || n < 1 || n > 200)) {
  throw new Error(`--limit must be an integer 1-200, got: ${raw}`);
}

Type guard

function isValidLimit(v) {
  if (v === undefined || v === null || v === '') return true;
  const n = Number(v);
  return Number.isInteger(n) && n >= 1 && n <= 200;
}

Try / catch

try {
  await cli.twitter.deviceFollow({ limit: raw });
} catch (e) {
  if (e instanceof ArgumentError) {
    console.error(`Bad --limit '${raw}': use an integer 1-200`);
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the device-follow command with --limit set to a non-numeric string (e.g. --limit abc), a float (e.g. --limit 2.5), a value below 1 (e.g. --limit 0), or a value above MAX_LIMIT=200 (e.g. --limit 500). Note whitespace-only strings and '0x10' style values also fail the integer check.

Common situations: Developers scripting the CLI with shell variables that are empty-but-quoted, copying limits from other twitter commands with higher caps (e.g. download.js allows up to 1000), or passing comma-separated lists or values with units like '50 tweets'.

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