{"record":{"id":"072a86d6a16014d0","repo":"jackwener/OpenCLI","slug":"limit-must-be-between-recommend-min-limit-and","errorCode":null,"errorMessage":"--limit must be between ${RECOMMEND_MIN_LIMIT} and ${RECOMMEND_MAX_LIMIT}, got ${parsed}","messagePattern":"--limit must be between (.+?) and (.+?), got (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"warning","filePath":"clis/toutiao/utils.js","lineNumber":32,"sourceCode":"    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(`--page must be an integer between ${ARTICLES_MIN_PAGE} and ${ARTICLES_MAX_PAGE}, got ${JSON.stringify(raw)}`);\n    }\n    if (parsed < ARTICLES_MIN_PAGE || parsed > ARTICLES_MAX_PAGE) {\n        throw new ArgumentError(`--page must be between ${ARTICLES_MIN_PAGE} and ${ARTICLES_MAX_PAGE}, got ${parsed}`);\n    }\n    return parsed;\n}\n\nexport function parseRecommendLimit(raw, fallback = 20) {\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 ${RECOMMEND_MIN_LIMIT} and ${RECOMMEND_MAX_LIMIT}, got ${JSON.stringify(raw)}`);\n    }\n    if (parsed < RECOMMEND_MIN_LIMIT || parsed > RECOMMEND_MAX_LIMIT) {\n        throw new ArgumentError(`--limit must be between ${RECOMMEND_MIN_LIMIT} and ${RECOMMEND_MAX_LIMIT}, got ${parsed}`);\n    }\n    return parsed;\n}\n\nexport function parseRecommendCategory(raw, fallback = '__all__') {\n    if (raw === undefined || raw === null || raw === '') return fallback;\n    const value = String(raw).trim();\n    if (!RECOMMEND_CATEGORIES.includes(value)) {\n        throw new ArgumentError(`--category must be one of ${RECOMMEND_CATEGORIES.join(', ')}, got ${JSON.stringify(raw)}`);\n    }\n    return value;\n}\n\nexport function parseHotLimit(raw, fallback = 30) {\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 ${HOT_MIN_LIMIT} and ${HOT_MAX_LIMIT}, got ${JSON.stringify(raw)}`);","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/toutiao/utils.js#L14-L50","documentation":"parseRecommendLimit validates the `--limit` option of the toutiao recommend CLI command. This specific throw fires only when the value IS a valid integer but falls outside the allowed range [RECOMMEND_MIN_LIMIT=1, RECOMMEND_MAX_LIMIT=50]. The library enforces this bound to keep the upstream request well-formed and avoid abusive or empty fetches.","triggerScenarios":"Calling the toutiao recommend command with an integer --limit < 1 (e.g. --limit 0, --limit -5) or > 50 (e.g. --limit 100). The value passed Number() and isInteger() checks but failed the min/max comparison.","commonSituations":"Developers copy-paging 'fetch more' scripts and guess --limit 100 expecting more rows; scripts computing limit = pageSize * pages accidentally yield 0 when pages is 0; shell variable interpolation producing an empty-adjacent 0 value.","solutions":["Pass an integer between 1 and 50 for --limit (default is 20).","Clamp the value in your script before invoking: Math.min(50, Math.max(1, n)).","Omit --limit entirely to use the default of 20.","If more than 50 items are needed, paginate multiple calls instead of raising the limit."],"exampleFix":"// before\ntoutiao recommend --limit 100\n// after\ntoutiao recommend --limit 50  # or paginate multiple calls","handlingStrategy":"validation","validationCode":"const n = Number(raw);\nif (!Number.isInteger(n) || n < 1 || n > 50) throw new RangeError(`--limit must be an integer between 1 and 50, got ${raw}`);","typeGuard":"const isValidLimit = (v) => Number.isInteger(v) && v >= 1 && v <= 50;","tryCatchPattern":"try {\n  parseRecommendLimit(raw);\n} catch (e) {\n  if (e instanceof ArgumentError) { console.error(e.message); process.exitCode = 2; }\n  else throw e;\n}","preventionTips":["Clamp user input with Math.min(50, Math.max(1, n)) before invoking.","Omit --limit to accept the default of 20.","Paginate instead of raising the limit above 50."],"tags":["cli","argument-validation","toutiao"],"backgroundTag":"cli-argument-out-of-range","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}