{"record":{"id":"042d8f1cdbe6f9a0","repo":"jackwener/OpenCLI","slug":"expand-rounds-must-be-an-integer-in-reddit-expa","errorCode":null,"errorMessage":"expand-rounds must be an integer in [${REDDIT_EXPAND_ROUNDS_MIN}, ${REDDIT_EXPAND_ROUNDS_MAX}].","messagePattern":"expand-rounds must be an integer in \\[(.+?), (.+?)\\]\\.","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/reddit/read.js","lineNumber":92,"sourceCode":"\n    if (raw.includes('/') || raw.startsWith('t1_')) {\n        throw new ArgumentError(\n            'Post ID must be a Reddit post id, t3_ fullname, or reddit.com post URL.',\n            'Use a bare post id like 1abc123, a fullname like t3_1abc123, or a full Reddit post URL.',\n        );\n    }\n\n    return normalizeBareRedditPostId(raw);\n}\n\nexport function parseExpandRounds(raw) {\n    if (raw === undefined || raw === null || raw === '') return DEFAULT_EXPAND_ROUNDS;\n    const n = Number(raw);\n    if (\n        !Number.isFinite(n) || !Number.isInteger(n)\n        || n < REDDIT_EXPAND_ROUNDS_MIN || n > REDDIT_EXPAND_ROUNDS_MAX\n    ) {\n        throw new ArgumentError(\n            `expand-rounds must be an integer in [${REDDIT_EXPAND_ROUNDS_MIN}, ${REDDIT_EXPAND_ROUNDS_MAX}].`,\n            `Got: ${raw}`,\n        );\n    }\n    return n;\n}\n\ncli({\n    site: 'reddit',\n    name: 'read',\n    access: 'read',\n    description: 'Read a Reddit post and its comments',\n    domain: 'reddit.com',\n    strategy: Strategy.COOKIE,\n    browser: true,\n    args: [\n        { name: 'post-id', required: true, positional: true, help: 'Post ID (e.g. 1abc123) or full URL' },\n        { name: 'sort', default: 'best', help: 'Comment sort: best, top, new, controversial, old, qa' },","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reddit/read.js#L74-L110","documentation":"parseExpandRounds validates the --expand-rounds option, which caps how many passes of /api/morechildren.json expansion are run. The value must be a finite integer within [REDDIT_EXPAND_ROUNDS_MIN, REDDIT_EXPAND_ROUNDS_MAX] = [1, 5]. Non-numeric, non-integer, out-of-range, NaN or Infinity inputs raise this ArgumentError with the offending value echoed back.","triggerScenarios":"Passing --expand-rounds 0, 6, 2.5, 'many', or an empty-ish value that Number() coerces to NaN (only undefined/null/'' fall back to the default of 2).","commonSituations":"Typo in a script flag (e.g. --expand-rounds=-1); copying a fractional default like 1.5 from a config; environment-variable substitution producing an empty or garbage string that is not exactly ''. ","solutions":["Set --expand-rounds to an integer between 1 and 5 (default is 2 when omitted).","If the value comes from a variable/env var, coerce and clamp it before passing, e.g. Math.min(5, Math.max(1, Math.round(Number(v)))).","Omit the flag entirely to use the default of 2."],"exampleFix":"// before\nreddit read 1abc123 --expand-rounds 10\n// after\nreddit read 1abc123 --expand-rounds 5","handlingStrategy":"validation","validationCode":"function clampExpandRounds(v, min = 1, max = 5, dflt = 2) {\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 Error(`expand-rounds must be int in [${min},${max}], got ${v}`);\n  return n;\n}","typeGuard":"const isValidExpandRounds = (v) =>\n  v === undefined || v === null || v === '' ||\n  (Number.isInteger(Number(v)) && Number(v) >= 1 && Number(v) <= 5);","tryCatchPattern":"try {\n  await redditRead(id, { expandRounds: rawRounds });\n} catch (e) {\n  if (/expand-rounds must be an integer/.test(e.message)) {\n    console.warn('Bad --expand-rounds, using default 2');\n    await redditRead(id, { expandRounds: 2 });\n  } else throw e;\n}","preventionTips":["Clamp user/config-supplied values into [1,5] with Math.round + Math.min/max before passing.","Omit the flag to get the sane default (2) instead of computing a value.","Validate env-var-sourced numbers with Number.isInteger before use."],"tags":["argument-validation","range-check","cli-options"],"backgroundTag":"parameter-out-of-range","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}