{"record":{"id":"af5906b309c8f43a","repo":"jackwener/OpenCLI","slug":"limit-must-be-an-integer-between-min-limit-an-af5906","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/reuters/utils.js","lineNumber":13,"sourceCode":"/**\n * Shared helpers for the reuters adapter.\n */\nimport { ArgumentError } from '@jackwener/opencli/errors';\n\nconst MIN_LIMIT = 1;\nconst MAX_LIMIT = 40;\n\nexport function parseLimit(raw, fallback = 10) {\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\n/**\n * Build the in-page IIFE that fetches the Reuters search API.\n *\n * Returns a raw envelope `{ ok, status, body, error? }` so that error-handling\n * lives in node space (not silently swallowed by `catch(e) {}` inside the\n * browser).\n */\nexport function buildSearchScript(query, count) {\n    return `\n    (async () => {\n      const apiQuery = JSON.stringify({","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reuters/utils.js#L1-L31","documentation":"parseLimit validates the --limit CLI option in the Reuters CLI. It throws ArgumentError when the raw value is supplied but cannot be interpreted as a finite integer (e.g. 'abc', '3.5', '10x'). This check runs before the range check, so non-numeric input never reaches the MIN/MAX comparison.","triggerScenarios":"Invoking the reuters CLI with --limit set to a non-integer string ('abc'), a decimal ('3.5'), or any value that Number() coerces to NaN/Infinity (e.g. --limit '', --limit 1e400, --limit '10x').","commonSituations":"Users pasting 'limit=5' style syntax, typos like 'lmit 5o', shell scripts interpolating empty or malformed variables into --limit, or passing floats copied from other tools.","solutions":["Pass an integer value for --limit, e.g. --limit 10.","Remove surrounding quotes/units or stray characters from the value.","If the value comes from a variable, echo it first to confirm it is a plain integer.","Omit --limit entirely to use the default fallback of 10."],"exampleFix":"// before\nreuters search \"ai\" --limit 3.5\n// after\nreuters search \"ai\" --limit 3","handlingStrategy":"validation","validationCode":"function isValidLimit(v) {\n  if (v === undefined || v === null || v === '') return true; // falls back to default\n  const n = Number(v);\n  return Number.isFinite(n) && Number.isInteger(n);\n}\nif (!isValidLimit(rawLimit)) throw new Error('limit must be an integer');","typeGuard":"const isInteger = (v) => typeof v === 'number' ? Number.isInteger(v) : Number.isFinite(Number(v)) && String(Number(v)) === String(v).trim();","tryCatchPattern":"try {\n  const limit = parseLimit(rawLimit);\n} catch (err) {\n  if (err instanceof ArgumentError) {\n    console.error(`Invalid --limit: ${err.message}. Using default 10.`);\n  } else throw err;\n}","preventionTips":["Validate numeric CLI args with a schema (zod/yargs number type) before dispatch.","Echo interpolated shell variables to confirm they are clean integers.","Prefer omitting --limit to accept the default.","Add a smoke test running the CLI with a valid --limit."],"tags":["cli","argument-validation","input-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}