jackwener/OpenCLI · error · ArgumentError

--limit must be an integer between 1 and 1000

Error message

--limit must be an integer between 1 and 1000

What it means

requireLimit in download.js coerces the --limit option (defaulting to 10 via value ?? 10) and throws ArgumentError unless it is an integer from 1 to 1000. This upper bound is much higher than device-follow's 200 because download loops fetch media in batches until the limit is reached.

Source

Thrown at clis/twitter/download.js:121

    withAuxiliaryUserLabels: true,
};

const USER_MEDIA_OPERATION = {
    queryId: USER_MEDIA_QUERY_ID,
    features: USER_MEDIA_FEATURES,
    fieldToggles: USER_MEDIA_FIELD_TOGGLES,
};

const USER_BY_SCREEN_NAME_OPERATION = {
    queryId: USER_BY_SCREEN_NAME_QUERY_ID,
    features: USER_BY_SCREEN_NAME_FEATURES,
    fieldToggles: USER_BY_SCREEN_NAME_FIELD_TOGGLES,
};

function requireLimit(value) {
    const limit = Number(value ?? 10);
    if (!Number.isInteger(limit) || limit < 1 || limit > 1000) {
        throw new ArgumentError('--limit must be an integer between 1 and 1000');
    }
    return limit;
}

function nextUserMediaFetchCount(limit, downloadedCount) {
    const remaining = limit - downloadedCount;
    if (remaining <= 0) return 0;
    const requested = remaining + 10;
    if (requested > 100) return 100;
    return requested;
}

async function downloadTwitterMedia(items, options) {
    const rows = await downloadMedia(items, options);
    return rows.map((row, index) => {
        const item = items[index] || {};
        return {
            index: row.index,

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass an integer between 1 and 1000, e.g. --limit 100
  2. Omit --limit to use the default of 10
  3. Fix shell interpolation so empty variables fall back to a number: --limit "${N:-50}"
  4. For more than 1000 items, run the command repeatedly with an offset/pagination strategy

Example fix

// before
cli twitter download --limit ""   # -> Number('') is 0 -> ArgumentError
// after
cli twitter download --limit "${LIMIT:-10}"
Defensive patterns

Strategy: validation

Validate before calling

const n = Number(raw ?? 10);
if (!Number.isInteger(n) || n < 1 || n > 1000) {
  throw new Error(`--limit must be an integer 1-1000, got: ${JSON.stringify(raw)}`);
}

Type guard

function isValidDownloadLimit(v) {
  const n = Number(v ?? 10);
  return Number.isInteger(n) && n >= 1 && n <= 1000;
}

Try / catch

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

Prevention

When it happens

Trigger: Calling the download command with --limit as a non-numeric string, a float, 0 or negative, or any integer above 1000. Also triggered by passing null-like placeholders other than actual undefined/null — note value ?? 10 only defaults on undefined/null, so empty string coerces to 0 and fails.

Common situations: Scripts exporting empty-string shell variables (--limit ""), copying --limit 2000 from batch-download recipes exceeding the cap, or typos like --limit 1o.

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