{"record":{"id":"818be7681bb8f4d7","repo":"jackwener/OpenCLI","slug":"limit-must-be-between-1-and-100-got-parsed-818be7","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/xiaohongshu/search.js","lineNumber":330,"sourceCode":"        !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,\n            option,\n            capability: value === definition.defaultValue\n                ? ''","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/search.js#L312-L348","documentation":"parseLimit additionally range-checks the parsed integer: --limit must be between 1 and 100 inclusive. If the value parses as an integer but falls outside that range, this ArgumentError is thrown with the parsed value in the message. This caps scrape size and prevents zero/negative limits.","triggerScenarios":"--limit 0, --limit -5, --limit 101, or --limit 1000 — any integer outside [1, 100].","commonSituations":"Pagination loops that increment a limit without clamping, users trying to fetch 'everything' with a huge limit, or off-by-one logic passing 0 meaning 'no extra'.","solutions":["Use a value between 1 and 100, e.g. --limit 100","Clamp the value in the calling code: Math.min(100, Math.max(1, n))","For larger result sets, paginate with multiple calls instead of raising the limit"],"exampleFix":"// before\nconst limit = userRequested; // e.g. 500\n// after\nconst limit = Math.min(100, Math.max(1, Number(userRequested) || 20));","handlingStrategy":"validation","validationCode":"const n = Number(rawLimit ?? 20);\nconst clamped = Math.min(100, Math.max(1, Math.trunc(n)));\nif (clamped !== n) console.warn(`--limit ${rawLimit} out of range, using ${clamped}`);","typeGuard":"const isLimitInRange = (v) => Number.isInteger(v) && v >= 1 && v <= 100;","tryCatchPattern":"try {\n  limit = parseLimit(rawLimit);\n} catch (e) {\n  if (e instanceof ArgumentError && /between 1 and 100/.test(e.message)) {\n    limit = Math.min(100, Math.max(1, Number(rawLimit) || 20));\n  } else throw e;\n}","preventionTips":["Clamp user-provided limits to [1, 100] before invoking the CLI","Paginate with repeated calls rather than inflating the limit","Guard pagination loops so counters never reach 0 or negatives","Document the 1–100 range where the option is exposed to end users"],"tags":["cli","argument-validation","range-check"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}