{"record":{"id":"5e51547a6a0b0743","repo":"jackwener/OpenCLI","slug":"limit-must-be-an-integer-between-min-limit-an-5e5154","errorCode":null,"errorMessage":"--limit must be an integer between ${MIN_LIMIT} and ${MAX_LIMIT}, got ${JSON.stringify(raw)}","messagePattern":"--limit must be an integer between (.+?) and (.+?), got (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/trip/utils.js","lineNumber":55,"sourceCode":"    const year = Number(m[1]);\n    const month = Number(m[2]);\n    const day = Number(m[3]);\n    if (month < 1 || month > 12 || day < 1 || day > 31) {\n        throw new ArgumentError(`--${name} has invalid month/day: ${value}`);\n    }\n    // Cross-check via UTC date math so 2026-02-30 doesn't pass.\n    const parsed = new Date(Date.UTC(year, month - 1, day));\n    if (parsed.getUTCFullYear() !== year || parsed.getUTCMonth() !== month - 1 || parsed.getUTCDate() !== day) {\n        throw new ArgumentError(`--${name} is not a real calendar date: ${value}`);\n    }\n    return value;\n}\n\nexport function parseListLimit(raw, fallback = 20) {\n    if (raw === undefined || raw === null || raw === '') return fallback;\n    const parsed = Number(raw);\n    if (!Number.isFinite(parsed) || !Number.isInteger(parsed)) {\n        throw new ArgumentError(`--limit must be an integer between ${MIN_LIMIT} and ${MAX_LIMIT}, got ${JSON.stringify(raw)}`);\n    }\n    if (parsed < MIN_LIMIT || parsed > MAX_LIMIT) {\n        throw new ArgumentError(`--limit must be between ${MIN_LIMIT} and ${MAX_LIMIT}, got ${parsed}`);\n    }\n    return parsed;\n}\n\nexport function buildFlightSearchUrl(fromCode, toCode, date) {\n    const params = new URLSearchParams({\n        dcity: fromCode.toLowerCase(),\n        acity: toCode.toLowerCase(),\n        ddate: date,\n        triptype: 'ow',\n        class: 'y',\n        quantity: '1',\n        locale: 'en_US',\n        curr: 'USD',\n    });","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trip/utils.js#L37-L73","documentation":"parseListLimit validates the --limit option as an integer; this error is thrown when the value is non-numeric, non-finite, or a non-integer (e.g. 12.5, 'abc', Infinity). The message advertises the accepted range via MIN_LIMIT/MAX_LIMIT constants.","triggerScenarios":"Calling limit (which delegates to parseListLimit) with --limit abc, --limit 12.5, --limit NaN, --limit 1e999, or an object/array that Number() coerces to NaN.","commonSituations":"Decimal values pasted from configs; unit suffixes like '50+' or '1k'; a variable containing a formatted number with currency symbols or thousands separators ('1,000').","solutions":["Pass a whole number, e.g. --limit 50","Remove formatting characters (commas, currency symbols, units) from the value","Round or floor the value before passing: --limit $(python3 -c 'print(int(x))') or Math.floor() in a wrapper","Check the accepted MIN_LIMIT/MAX_LIMIT in the CLI help to pick a valid integer"],"exampleFix":"// before\nclis-trip flights --from LON --to NYC --depart 2026-10-01 --limit 1,000\n// after\nclis-trip flights --from LON --to NYC --depart 2026-10-01 --limit 100","handlingStrategy":"validation","validationCode":"function isValidLimit(v) {\n  const n = Number(v);\n  return Number.isFinite(n) && Number.isInteger(n);\n}\nif (limit !== undefined && !isValidLimit(limit)) throw new Error(`--limit must be an integer, got ${JSON.stringify(limit)}`);","typeGuard":"function isIntegerLike(v) {\n  const n = Number(v);\n  return Number.isFinite(n) && Number.isInteger(n);\n}","tryCatchPattern":"try {\n  runTripCli(['hotels', '--limit', limit]);\n} catch (err) {\n  if (err instanceof ArgumentError && /--limit must be an integer/.test(err.message)) {\n    console.error(`Invalid --limit: ${err.message}. Pass a whole number.`);\n    process.exitCode = 2;\n  } else throw err;\n}","preventionTips":["Coerce with Number() and check Number.isInteger before passing","Strip formatting characters (commas, symbols, units) from config values","Use Math.floor/Math.round for computed limits","Document that --limit accepts plain integers only"],"tags":["cli","argument-validation","integer"],"backgroundTag":"invalid-cli-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}