{"record":{"id":"ec8fa7a3f65d7b51","repo":"jackwener/OpenCLI","slug":"limit-must-be-an-integer-in-1-reddit-home-max","errorCode":null,"errorMessage":"limit must be an integer in [1, ${REDDIT_HOME_MAX_LIMIT}].","messagePattern":"limit must be an integer in \\[1, (.+?)\\]\\.","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/reddit/home.js","lineNumber":10,"sourceCode":"import { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\nimport { cli, Strategy } from '@jackwener/opencli/registry';\n\nconst REDDIT_HOME_MAX_LIMIT = 100;\n\nexport function parseRedditHomeLimit(raw) {\n    if (raw === undefined || raw === null || raw === '') return 25;\n    const n = Number(raw);\n    if (!Number.isFinite(n) || !Number.isInteger(n) || n < 1 || n > REDDIT_HOME_MAX_LIMIT) {\n        throw new ArgumentError(\n            `limit must be an integer in [1, ${REDDIT_HOME_MAX_LIMIT}].`,\n            `Got: ${raw}`,\n        );\n    }\n    return n;\n}\n\nexport function decodeRedditHtml(value) {\n    if (typeof value !== 'string' || !value) return '';\n    return value\n        .replace(/&amp;/g, '&')\n        .replace(/&lt;/g, '<')\n        .replace(/&gt;/g, '>')\n        .replace(/&quot;/g, '\"')\n        .replace(/&#x27;/gi, \"'\")\n        .replace(/&#39;/g, \"'\");\n}\n","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reddit/home.js#L1-L28","documentation":"ArgumentError thrown by parseRedditHomeLimit when the `limit` argument of `reddit home` is not an integer within [1, 100]. Empty/undefined/null values default to 25; anything else non-numeric, non-integer, <1, or >100 is rejected with the actual value echoed back.","triggerScenarios":"Passing limit=0, a negative number, a float like 25.5, a non-numeric string like 'all' or '2e2' (Number('2e2')=200 -> out of range... actually 200>100), or any value above REDDIT_HOME_MAX_LIMIT=100.","commonSituations":"Users copying Reddit's web max (100) but off-by-one to 101; passing '25 ' with whitespace-plus-chars; scripts interpolating an unset variable producing 'undefined'; wanting 'all posts' and passing a huge limit.","solutions":["Pass an integer between 1 and 100 inclusive, e.g. --limit 50.","Omit the flag entirely to use the default of 25.","Coerce/validate the value in your wrapper script before invoking the CLI.","If you need more than 100 posts, paginate by re-running with different sort/time filters rather than raising limit."],"exampleFix":"// before\nopencli reddit home --limit 250\n// after\nopencli reddit home --limit 100","handlingStrategy":"validation","validationCode":"function parseRedditHomeLimitSafe(raw) {\n  if (raw === undefined || raw === null || raw === '') return 25;\n  const n = Number(raw);\n  if (!Number.isFinite(n) || !Number.isInteger(n) || n < 1 || n > 100) {\n    throw new RangeError(`limit must be an integer in [1, 100], got: ${raw}`);\n  }\n  return n;\n}\n// call before invoking the CLI\nparseRedditHomeLimitSafe(process.env.LIMIT);","typeGuard":"function isValidRedditHomeLimit(v) {\n  const n = Number(v);\n  return Number.isFinite(n) && Number.isInteger(n) && n >= 1 && n <= 100;\n}","tryCatchPattern":"try {\n  await opencli.reddit.home({ limit: userLimit });\n} catch (e) {\n  if (/limit must be an integer/.test(e.message)) {\n    console.error('Please pass an integer 1-100; defaulting to 25.');\n    return opencli.reddit.home({ limit: 25 });\n  }\n  throw e;\n}","preventionTips":["Clamp user input: Math.min(100, Math.max(1, Math.floor(n))).","Omit the flag to accept the default of 25.","Validate env/config values interpolated into CLI args before running.","Remember the max is 100, matching Reddit's per-request listing cap."],"tags":["validation","arguments","reddit","input"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}