{"record":{"id":"fc3ea894df835c14","repo":"jackwener/OpenCLI","slug":"limit-must-be-an-integer-in-1-reddit-subscribe","errorCode":null,"errorMessage":"limit must be an integer in [1, ${REDDIT_SUBSCRIBED_MAX_LIMIT}].","messagePattern":"limit must be an integer in \\[1, (.+?)\\]\\.","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"warning","filePath":"clis/reddit/subscribed.js","lineNumber":11,"sourceCode":"import { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nimport { BROWSER_JSON_SNIFF_FN, throwIfLoginWall } from '@jackwener/opencli/utils';\n\nexport const REDDIT_SUBSCRIBED_MAX_LIMIT = 1000;\n\nexport function parseRedditSubscribedLimit(raw) {\n    if (raw === undefined || raw === null || raw === '') return 100;\n    const n = Number(raw);\n    if (!Number.isFinite(n) || !Number.isInteger(n) || n < 1 || n > REDDIT_SUBSCRIBED_MAX_LIMIT) {\n        throw new ArgumentError(\n            `limit must be an integer in [1, ${REDDIT_SUBSCRIBED_MAX_LIMIT}].`,\n            `Got: ${raw}`,\n        );\n    }\n    return n;\n}\n\nexport function unwrapEvaluateResult(payload) {\n    if (payload && typeof payload === 'object' && !Array.isArray(payload) && 'session' in payload && 'data' in payload) {\n        return payload.data;\n    }\n    return payload;\n}\n\nfunction mapSubredditRow(entry, index) {\n    const data = entry?.data;\n    if (!data || typeof data !== 'object') {\n        throw new CommandExecutionError(`Reddit subscriptions row ${index + 1} was missing data.`);","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reddit/subscribed.js#L1-L29","documentation":"ArgumentError thrown by parseRedditSubscribedLimit when the `limit` argument is not an integer in [1, 1000]. The limit controls how many subscribed subreddits to fetch (auto-paginating in pages of 100), and the library validates it up front to fail fast instead of mid-pagination.","triggerScenarios":"Passing limit values like 0, -5, 1001, 12.5, 'abc', or NaN to the reddit subscribed command; omitting it is fine (defaults to 100), but any present value must parse as a finite integer within range.","commonSituations":"Users assuming '0' means 'unlimited'; copying limits above Reddit's max; passing a string with whitespace or units ('100 subs'); config files with float or string values.","solutions":["Pass an integer between 1 and 1000, e.g. limit=100","Use 'all-like' behavior by passing 1000 (the maximum) rather than 0 or a huge number","Trim/normalize the input: strip whitespace and units so Number(raw) is a clean integer","If sourcing limit from config/env, coerce and validate before calling, e.g. Number.isInteger(Number(v))"],"exampleFix":"// before\nreddit subscribed --limit 0        // throws\nreddit subscribed --limit 'all'    // throws\n// after\nreddit subscribed --limit 1000     // max valid value","handlingStrategy":"validation","validationCode":"const REDDIT_SUBSCRIBED_MAX_LIMIT = 1000;\nfunction validLimit(v){\n  if (v === undefined || v === null || v === '') return 100;\n  const n = Number(v);\n  return Number.isInteger(n) && n >= 1 && n <= REDDIT_SUBSCRIBED_MAX_LIMIT ? n : null;\n}","typeGuard":"function isValidLimit(v){\n  if (v === undefined || v === null || v === '') return true;\n  const n = Number(v);\n  return Number.isInteger(n) && n >= 1 && n <= 1000;\n}","tryCatchPattern":"try { await cli.redditSubscribed({ limit }); }\ncatch (e) { if (e.name === 'ArgumentError' && e.message.includes('limit must be an integer')) { console.error(`bad limit ${limit}; use 1-1000`); return; } throw e; }","preventionTips":["Clamp user-supplied limits: Math.min(1000, Math.max(1, n)) before passing","Never use 0 to mean 'unlimited' — use 1000 (the max)","Coerce config/env strings with Number() and Number.isInteger checks","Reuse the exported parseRedditSubscribedLimit for pre-validation in embeddings"],"tags":["reddit","argument-validation","input-validation"],"backgroundTag":"invalid-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}