jackwener/OpenCLI · error · ArgumentError

${name} must be <= ${max}

Error message

${name} must be <= ${max}

What it means

After validating positivity and integrality, requireLimit rejects values greater than the configured max and throws this ArgumentError. The cap (e.g. MAX_PAGES = 4 upstream) exists to bound how many pages the CLI will fetch, keeping runtime and rate-limit exposure predictable.

Source

Thrown at clis/tiktok/utils.js:33

    getErrorMessage,
} from '@jackwener/opencli/errors';

export const TIKTOK_AID = '1988';
export const TIKTOK_HOST = 'https://www.tiktok.com';
export const SERVER_PAGE_MAX = 30;
export const MAX_PAGES = 4;

export function requireLimit(value, { fallback, max, name = 'limit' }) {
    const raw = value ?? fallback;
    const parsed = Number(raw);
    if (!Number.isInteger(parsed) || parsed <= 0) {
        throw new ArgumentError(
            `${name} must be a positive integer`,
            `Example: --${name} ${fallback}`,
        );
    }
    if (parsed > max) {
        throw new ArgumentError(
            `${name} must be <= ${max}`,
            `Example: --${name} ${max}`,
        );
    }
    return parsed;
}

export function normalizeUsername(value) {
    const username = String(value ?? '').trim().replace(/^@+/, '');
    if (!username) {
        throw new ArgumentError(
            'username is required',
            'Example: opencli tiktok following <username>',
        );
    }
    if (!/^[A-Za-z0-9._-]+$/.test(username)) {
        throw new ArgumentError(
            'username contains unsupported characters',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Lower the value to at most the stated max (the error's example shows the max, e.g. --limit <max>).
  2. If you need more data, paginate: call the command repeatedly, or use cursor/offset options if available.
  3. Clamp programmatic values: Math.min(requested, max) before invoking.
  4. Check the command's help output for the option's documented maximum.

Example fix

// before
opencli tiktok user someone --limit 100
// after (max enforced by the CLI, paginate instead)
opencli tiktok user someone --limit 4
opencli tiktok user someone --limit 4 --cursor <next>
Defensive patterns

Strategy: validation

Validate before calling

function clampLimit(v, max) {
  const n = Number(v);
  if (!Number.isInteger(n) || n <= 0) throw new Error('limit must be a positive integer');
  return Math.min(n, max); // enforce max BEFORE calling the CLI
}

Type guard

const withinMax = (v, max) => Number.isInteger(Number(v)) && Number(v) > 0 && Number(v) <= max;

Try / catch

try {
  await cli.tiktok.user(username, { limit });
} catch (e) {
  const m = /must be <= (\d+)/.exec(e.message);
  if (m) {
    const max = Number(m[1]);
    await cli.tiktok.user(username, { limit: Math.min(limit, max) });
  } else throw e;
}

Prevention

When it happens

Trigger: Passing a flag value above the option's maximum, e.g. --limit 50 when max is 20, or requesting more pages than MAX_PAGES allows; constructing limits dynamically (items.length) without clamping.

Common situations: Users assuming 'more is better' and setting very large limits; scripts that pass an unbounded page count from config; misreading which unit the flag uses (items vs pages) leading to inflated values.

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