{"record":{"id":"f6f18dbc070077af","repo":"jackwener/OpenCLI","slug":"limit-must-be-between-1-and-100-got-parsed","errorCode":null,"errorMessage":"--limit must be between 1 and 100, got ${parsed}","messagePattern":"--limit must be between 1 and 100, got (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/rednote/search.js","lineNumber":19,"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\n * of (and as a fallback, alongside) the inline `登录后查看搜索结果` text.\n * The modal detector filters hidden / zero-area elements to avoid false\n * positives on background dialogs.","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/rednote/search.js#L1-L37","documentation":"parseLimit throws ArgumentError when the value is a finite integer but outside the 1-100 window accepted by rednote search (0, negatives, or >100). The message embeds the coerced number. Search results are capped at 100 by design.","triggerScenarios":"Passing --limit 0, --limit 101, or any negative integer to the rednote search command.","commonSituations":"Users wanting 'everything' passing a huge number like 1000, batch scripts computing page sizes that exceed the cap, or porting code from other rednote commands (notifications/user) whose limits are unbounded above.","solutions":["Use --limit within 1-100; clamp with Math.min(100, Math.max(1, n))","If more results are needed, paginate using different queries/keywords rather than raising the cap","Adjust batch scripts to slice requests into <=100 chunks"],"exampleFix":"// before\nconst limit = totalWanted; // e.g. 500\n// after\nconst limit = Math.min(100, Math.max(1, totalWanted)); // paginate for the rest","handlingStrategy":"validation","validationCode":"const n = Number(raw); if (Number.isInteger(n) && (n < 1 || n > 100)) throw new Error(`--limit must be between 1 and 100, got ${n}`);","typeGuard":"const inSearchRange = (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)) { return runSearch({ query, limit: Math.min(100, Math.max(1, limit)) }); } throw e; }","preventionTips":["Clamp with Math.min(100, Math.max(1, n)) in wrappers","Split bulk requests into pages of at most 100","Do not copy unbounded-limit assumptions from other rednote subcommands"],"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"}