{"record":{"id":"4985de9a1981a00c","repo":"jackwener/OpenCLI","slug":"limit-must-be-an-integer-between-1-and-100-got","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/rednote/search.js","lineNumber":16,"sourceCode":"/**\n * Rednote search — international mirror of xiaohongshu/search.\n *\n * Reuses the DOM-extraction IIFE from `../xiaohongshu/search.js`; only the\n * web host and the login-gate detection differ. See issue #1136 for the\n * 1:1 comparison between the two frontends.\n */\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { buildScrollUntilJs, buildSearchExtractJs, noteIdToDate } from '../xiaohongshu/search.js';\nimport { unwrapEvaluateResult } from '../xiaohongshu/shared.js';\n\nfunction parseLimit(raw) {\n    const parsed = Number(raw);\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}\nfunction requireSearchRows(payload) {\n    const rows = unwrapEvaluateResult(payload);\n    if (!Array.isArray(rows)) {\n        throw new CommandExecutionError('Unexpected Rednote search extraction payload shape; expected an array of rows.');\n    }\n    return rows;\n}\n\n/**\n * Wait for search results or login wall using MutationObserver (max 5s).\n *\n * Differs from xiaohongshu by detecting a full-screen login modal instead","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/rednote/search.js#L1-L34","documentation":"The rednote search command's parseLimit requires --limit to coerce to a finite integer between 1 and 100 (no default coercion of null here; undefined becomes NaN). It throws ArgumentError naming the full valid range whenever the raw value is non-numeric, a float, or otherwise unparseable.","triggerScenarios":"Calling rednote search with --limit 'abc', --limit 3.7, --limit '' , or omitting a value in a context where no default is applied so Number(undefined) = NaN.","commonSituations":"Copy-pasted commands where the number got dropped, scripts interpolating empty variables, users assuming search allows unlimited results (it is hard-capped at 100), or confusion with other rednote commands whose parseLimit defaults to 15/20.","solutions":["Pass an integer from 1 to 100, e.g. --limit 50","Remember search has no implicit default here in some paths; always pass --limit explicitly","Validate with Number.isInteger(Number(v)) && v>=1 && v<=100 before invoking"],"exampleFix":"// before\nrun(['rednote','search','--query','coffee','--limit', raw]);\n// after\nconst n = Number(raw);\nif (!Number.isInteger(n) || n < 1 || n > 100) throw new Error('limit must be 1-100');\nrun(['rednote','search','--query','coffee','--limit', n]);","handlingStrategy":"validation","validationCode":"const assertSearchLimit = (raw) => { const n = Number(raw); if (!Number.isFinite(n) || !Number.isInteger(n) || n < 1 || n > 100) throw new Error('--limit must be an integer between 1 and 100'); return n; };","typeGuard":"const isValidSearchLimit = (v) => { const n = Number(v); return Number.isInteger(n) && n >= 1 && n <= 100; };","tryCatchPattern":"try { await runSearch({ query, limit }); } catch (e) { if (e instanceof ArgumentError && /between 1 and 100/.test(e.message)) { console.error('Usage: --limit 1..100'); process.exitCode = 2; return; } throw e; }","preventionTips":["Clamp user-provided limits to [1,100] before invoking search","Always pass --limit explicitly for search (no reliable default in all paths)","Remember search caps at 100; paginate with narrower queries for more"],"tags":["cli","argument-validation","range-check"],"backgroundTag":"invalid-cli-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}