{"record":{"id":"f7967cc781f1a1d7","repo":"jackwener/OpenCLI","slug":"limit-must-be-an-integer-between-recommend-min","errorCode":null,"errorMessage":"--limit must be an integer between ${RECOMMEND_MIN_LIMIT} and ${RECOMMEND_MAX_LIMIT}, got ${JSON.stringify(raw)}","messagePattern":"--limit must be an integer between (.+?) and (.+?), got (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/toutiao/utils.js","lineNumber":29,"sourceCode":"const RECOMMEND_MAX_LIMIT = 50;\n\nexport function parseArticlesPage(raw, fallback = 1) {\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(`--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;","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/toutiao/utils.js#L11-L47","documentation":"This ArgumentError is thrown by parseRecommendLimit when the --limit value is provided but is not a finite integer. It is the type-check branch (before the range check) and includes the JSON-stringified raw input to make the offending value obvious.","triggerScenarios":"Running the recommend command with `--limit twenty`, `--limit 12.5`, `--limit 1,000`, or programmatically passing a non-integer to parseRecommendLimit. Empty/undefined/null values do NOT trigger it (fallback 20 applies).","commonSituations":"Entering formatted numbers with thousands separators ('1,000'); decimal limits ('20.5'); shell variables containing garbage; confusing --limit with a page number.","solutions":["Pass a plain integer within [RECOMMEND_MIN_LIMIT, RECOMMEND_MAX_LIMIT], e.g. `--limit 30`.","Strip formatting characters (commas, spaces) from the value.","In scripts, validate with Number.isInteger(Number(x)) before calling.","Omit --limit to use the default of 20."],"exampleFix":"// before\ntoutiao recommend --limit 1,000\n// after\ntoutiao recommend --limit 30","handlingStrategy":"validation","validationCode":"function validateLimit(raw) {\n  if (raw === undefined || raw === null || raw === '') return 20; // default\n  const n = Number(String(raw).replace(/[,\\s]/g, ''));\n  if (!Number.isInteger(n)) throw new TypeError(`--limit must be an integer, got ${JSON.stringify(raw)}`);\n  return n;\n}","typeGuard":"function isIntegerLimit(v) {\n  return typeof v === 'number' && Number.isInteger(v);\n}","tryCatchPattern":"try {\n  await recommend({ limit: rawLimit });\n} catch (e) {\n  if (e instanceof ArgumentError && e.message.startsWith('--limit must be an integer')) {\n    console.error(`Invalid --limit value; pass a plain integer like --limit 20`);\n    process.exitCode = 2;\n    return;\n  }\n  throw e;\n}","preventionTips":["Strip formatting (commas, spaces) from numeric input before passing.","Reject decimals early in scripts — limits must be whole numbers.","Omit --limit to use the built-in default of 20.","Sanitize environment/CI variables used to build CLI arguments."],"tags":["argument-validation","cli","input-error"],"backgroundTag":"invalid-argument-type","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}