{"record":{"id":"aeea573a3f3b9e40","repo":"jackwener/OpenCLI","slug":"limit-must-be-an-integer-between-1-and-100-got-aeea57","errorCode":null,"errorMessage":"--limit must be an integer between 1 and 100, got ${JSON.stringify(raw)}","messagePattern":"--limit must be an integer between 1 and 100, got (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/search.js","lineNumber":327,"sourceCode":"    const result = unwrapEvaluateResult(payload);\n    const diag = result?.diag;\n    if (!result || typeof result !== 'object' || Array.isArray(result) || !Array.isArray(result.rows) ||\n        !diag || typeof diag !== 'object' || Array.isArray(diag) ||\n        typeof diag.securityBlock !== 'boolean' || typeof diag.stopReason !== 'string' ||\n        !Number.isFinite(diag.scrollHeight) || diag.scrollHeight < 0 ||\n        !Number.isFinite(diag.clientHeight) || diag.clientHeight < 0 ||\n        !Number.isSafeInteger(diag.cardCount) || diag.cardCount < 0 ||\n        !(diag.feedClientHeight === null || (Number.isFinite(diag.feedClientHeight) && diag.feedClientHeight >= 0)) ||\n        !Number.isSafeInteger(diag.distinctCardTops) || diag.distinctCardTops < 0) {\n        throw new CommandExecutionError('Unexpected Xiaohongshu search harvest payload shape; expected rows plus typed diagnostics.');\n    }\n    result.rows = result.rows.map((row, index) => requireTrustedHarvestRow(row, index, webHost));\n    return result;\n}\nexport function parseLimit(raw) {\n    const parsed = Number(raw ?? 20);\n    if (!Number.isFinite(parsed) || !Number.isInteger(parsed)) {\n        throw new ArgumentError(`--limit must be an integer between 1 and 100, got ${JSON.stringify(raw)}`);\n    }\n    if (parsed < 1 || parsed > 100) {\n        throw new ArgumentError(`--limit must be between 1 and 100, got ${parsed}`);\n    }\n    return parsed;\n}\n\nfunction resolveSearchFilters(kwargs) {\n    return SEARCH_FILTERS.map((definition) => {\n        const value = kwargs[definition.arg] ?? definition.defaultValue;\n        const option = typeof value === 'string' ? definition.options[value] : undefined;\n        if (!option) {\n            throw new ArgumentError(\n                `--${definition.arg} must be one of: ${Object.keys(definition.options).join(', ')}, got ${JSON.stringify(value)}`,\n            );\n        }\n        return {\n            group: definition.group,","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/search.js#L309-L345","documentation":"parseLimit converts the --limit CLI argument (defaulting to 20) into an integer. If the raw value is not a finite number (e.g. 'abc' or '1,5'), it throws this ArgumentError with the raw value JSON-stringified. It is a strict argument-validation guard so downstream scraping only receives a usable count.","triggerScenarios":"Calling the CLI with --limit abc, --limit '' (empty string), --limit 3.5, or passing a non-numeric string programmatically into the limit option; Number() on such inputs yields NaN so the isFinite/isInteger check fails.","commonSituations":"Shell quoting mistakes (--limit \"1 0\"), copy-pasting values with units (--limit 20x), locale-formatted numbers with commas, or scripts interpolating undefined/malformed variables into the argument.","solutions":["Pass a plain integer string, e.g. --limit 20","Quote/escape the value in the shell so spaces or special characters don't corrupt it","Validate/trim the value in the calling script before forwarding it to the CLI","If a default is desired, omit --limit entirely (defaults to 20)"],"exampleFix":"// before\ncli --search \"coffee\" --limit 3.5\n// after\ncli --search \"coffee\" --limit 3","handlingStrategy":"validation","validationCode":"const rawLimit = process.argv[/* --limit value */];\nconst n = Number(rawLimit);\nif (!Number.isFinite(n) || !Number.isInteger(n)) {\n  throw new Error(`--limit must be an integer, got ${JSON.stringify(rawLimit)}`);\n}","typeGuard":"const isValidRawLimit = (v) =>\n  v === undefined || v === null ||\n  (typeof v === 'string' && v.trim() !== '' && Number.isInteger(Number(v)));","tryCatchPattern":"try {\n  limit = parseLimit(rawLimit);\n} catch (e) {\n  if (e instanceof ArgumentError) {\n    console.error(e.message + ' — using default 20');\n    limit = 20;\n  } else throw e;\n}","preventionTips":["Quote --limit values in shell scripts to avoid stray characters","Sanitize interpolated variables before passing them as CLI args","Prefer omitting --limit when the default (20) is acceptable","Add CLI arg parsing with typed flags (e.g. a parser library) to catch this before the library does"],"tags":["cli","argument-validation","input-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}