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 in clis/chess/games.js validates the --limit argument: it must be an integer between 1 and MAX_LIMIT (100) or omitted/empty (defaulting to 10). Non-numeric strings, floats, zero, negatives, or values above 100 throw ArgumentError before any network call is made.

Source

Thrown at clis/chess/games.js:16

/**
 * Chess.com recent games from monthly archives. Walks the archive
 * list newest-first and fetches as few months as needed to fill --limit.
 */
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
import { chessApi, validateUsername, mapGameRow } from './utils.js';

const MAX_LIMIT = 100;
const MAX_ARCHIVE_FETCHES = 6;

function parseLimit(value) {
    if (value === undefined || value === null || value === '') return 10;
    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;
}

cli({
    site: 'chess',
    name: 'games',
    access: 'read',
    description: 'Chess.com recent games for a player, newest first',
    domain: 'api.chess.com',
    strategy: Strategy.PUBLIC,
    browser: false,
    args: [
        { name: 'username', type: 'string', required: true, positional: true, help: 'Chess.com username' },
        { name: 'limit', type: 'int', default: 10, help: `Number of recent games (1-${MAX_LIMIT})` },
    ],
    columns: ['date', 'time_class', 'rated', 'my_color', 'my_rating', 'my_result', 'opponent', 'opponent_rating', 'accuracy_white', 'accuracy_black', 'eco', 'opening_name', 'url'],
    func: async (kwargs) => {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass an integer between 1 and 100, or omit --limit to use the default of 10
  2. Clamp/validate user-supplied values in your script before passing them (Math.min(100, Math.max(1, n)) and Number.isInteger check)
  3. If you need more than 100 games, call the command multiple times or fetch the archives endpoint directly

Example fix

// before
const limit = process.env.LIMIT; // '250'
await runGames({ limit });
// after
const n = Math.trunc(Number(process.env.LIMIT));
const limit = Number.isInteger(n) ? Math.min(100, Math.max(1, n)) : 10;
await runGames({ limit });
Defensive patterns

Strategy: validation

Validate before calling

function sanitizeLimit(v, { min = 1, max = 100, dflt = 10 } = {}) {
  if (v === undefined || v === null || v === '') return dflt;
  const n = Number(v);
  if (!Number.isInteger(n) || n < min || n > max) throw new RangeError(`limit must be an integer ${min}-${max}`);
  return n;
}

Type guard

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

Try / catch

try {
  await gamesCmd({ username, limit });
} catch (e) {
  if (e.name === 'ArgumentError' && /--limit/.test(e.message)) { console.error('Usage: --limit 1-100'); process.exitCode = 2; return; }
  throw e;
}

Prevention

When it happens

Trigger: Calling the chess games command with --limit as: a non-integer string ('abc'), a float ('2.5'), a number <= 0, or a number > 100 (e.g. --limit 500).

Common situations: Scripts computing the limit from user input or environment variables without validation; copy-pasted commands with units ('--limit 50 games'); assuming the cap is unlimited and requesting thousands of games.

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