{"record":{"id":"65631c8de83a16e7","repo":"jackwener/OpenCLI","slug":"limit-must-be-an-integer-between-1-and-max-lim","errorCode":null,"errorMessage":"--limit must be an integer between 1 and ${MAX_LIMIT}","messagePattern":"--limit must be an integer between 1 and (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/chess/games.js","lineNumber":16,"sourceCode":"/**\n * Chess.com recent games from monthly archives. Walks the archive\n * list newest-first and fetches as few months as needed to fill --limit.\n */\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\nimport { chessApi, validateUsername, mapGameRow } from './utils.js';\n\nconst MAX_LIMIT = 100;\nconst MAX_ARCHIVE_FETCHES = 6;\n\nfunction parseLimit(value) {\n    if (value === undefined || value === null || value === '') return 10;\n    const limit = Number(value);\n    if (!Number.isInteger(limit) || limit < 1 || limit > MAX_LIMIT) {\n        throw new ArgumentError(`--limit must be an integer between 1 and ${MAX_LIMIT}`);\n    }\n    return limit;\n}\n\ncli({\n    site: 'chess',\n    name: 'games',\n    access: 'read',\n    description: 'Chess.com recent games for a player, newest first',\n    domain: 'api.chess.com',\n    strategy: Strategy.PUBLIC,\n    browser: false,\n    args: [\n        { name: 'username', type: 'string', required: true, positional: true, help: 'Chess.com username' },\n        { name: 'limit', type: 'int', default: 10, help: `Number of recent games (1-${MAX_LIMIT})` },\n    ],\n    columns: ['date', 'time_class', 'rated', 'my_color', 'my_rating', 'my_result', 'opponent', 'opponent_rating', 'accuracy_white', 'accuracy_black', 'eco', 'opening_name', 'url'],\n    func: async (kwargs) => {","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/chess/games.js#L1-L34","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Pass an integer between 1 and 100, or omit --limit to use the default of 10","Clamp/validate user-supplied values in your script before passing them (Math.min(100, Math.max(1, n)) and Number.isInteger check)","If you need more than 100 games, call the command multiple times or fetch the archives endpoint directly"],"exampleFix":"// before\nconst limit = process.env.LIMIT; // '250'\nawait runGames({ limit });\n// after\nconst n = Math.trunc(Number(process.env.LIMIT));\nconst limit = Number.isInteger(n) ? Math.min(100, Math.max(1, n)) : 10;\nawait runGames({ limit });","handlingStrategy":"validation","validationCode":"function sanitizeLimit(v, { min = 1, max = 100, dflt = 10 } = {}) {\n  if (v === undefined || v === null || v === '') return dflt;\n  const n = Number(v);\n  if (!Number.isInteger(n) || n < min || n > max) throw new RangeError(`limit must be an integer ${min}-${max}`);\n  return n;\n}","typeGuard":"function isValidLimit(v) { const n = Number(v); return Number.isInteger(n) && n >= 1 && n <= 100; }","tryCatchPattern":"try {\n  await gamesCmd({ username, limit });\n} catch (e) {\n  if (e.name === 'ArgumentError' && /--limit/.test(e.message)) { console.error('Usage: --limit 1-100'); process.exitCode = 2; return; }\n  throw e;\n}","preventionTips":["Validate/clamp limit values at the edge of your script before passing CLI args","Use string-to-number coercion carefully; '2.5' and 'abc' both fail Number.isInteger","Remember the hard cap of 100; batch multiple calls for more history"],"tags":["argument-validation","input-validation","cli-args"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}