{"record":{"id":"7ff588d897ea6642","repo":"jackwener/OpenCLI","slug":"limit-must-be-between-min-limit-and-max-lim","errorCode":null,"errorMessage":"--limit must be between ${MIN_LIMIT} and ${MAX_LIMIT}, got ${parsed}","messagePattern":"--limit must be between (.+?) and (.+?), got (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/reuters/utils.js","lineNumber":16,"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({\n        keyword: ${JSON.stringify(query)},\n        offset: 0,\n        orderby: 'display_date:desc',","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reuters/utils.js#L1-L34","documentation":"parseLimit also enforces the allowed range for --limit: values must be between MIN_LIMIT and MAX_LIMIT (MAX_LIMIT is 40 in the source). It throws ArgumentError when the value is a valid integer but falls outside that range.","triggerScenarios":"Invoking the reuters CLI with an integer --limit below MIN_LIMIT (e.g. --limit 0) or above 40 (e.g. --limit 100).","commonSituations":"Users trying to fetch more results than the CLI caps at (--limit 500), scripts using limit=0 as 'unlimited', or copying page-size conventions from other APIs where 0 or 1000 are valid.","solutions":["Use an integer within the allowed range, e.g. --limit 10 through --limit 40.","If more results are needed, paginate or run the command multiple times instead of raising --limit.","Use a positive non-zero value; 0 is below the minimum.","Check the CLI help for the exact MIN/MAX bounds."],"exampleFix":"// before\nreuters search \"ai\" --limit 100\n// after\nreuters search \"ai\" --limit 40","handlingStrategy":"validation","validationCode":"function limitInRange(v, min = 1, max = 40) {\n  const n = Number(v);\n  return Number.isInteger(n) && n >= min && n <= max;\n}\nif (!limitInRange(rawLimit)) rawLimit = 10; // or clamp","typeGuard":"const inRange = (v, min, max) => { const n = Number(v); return Number.isInteger(n) && n >= min && n <= max; };","tryCatchPattern":"try {\n  const limit = parseLimit(rawLimit);\n} catch (err) {\n  if (err instanceof ArgumentError) {\n    console.warn('limit out of range, clamping to 40');\n    limit = 40;\n  } else throw err;\n}","preventionTips":["Clamp values instead of erroring in wrapper scripts.","Remember the max is 40; paginate for larger result sets.","Document the bounds in scripts/READMEs that pass --limit.","Never use 0 as a sentinel for 'unlimited'."],"tags":["cli","argument-validation","range-check"],"backgroundTag":"value-out-of-range","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}