{"record":{"id":"43b4b0bed07192c9","repo":"jackwener/OpenCLI","slug":"limit-must-be-between-1-and-100-got-parsed-43b4b0","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":"warning","filePath":"clis/xiaohongshu/collection-helpers.js","lineNumber":39,"sourceCode":"\nfunction isObject(value) {\n    return value && typeof value === 'object' && !Array.isArray(value);\n}\n\nexport function unwrapBrowserResult(payload) {\n    if (isObject(payload) && 'session' in payload && 'data' in payload) {\n        return payload.data;\n    }\n    return payload;\n}\n\nexport function parseCollectionLimit(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\nexport function readSelfUserIdFromState(state) {\n    const unwrapped = unwrapBrowserResult(state);\n    const user = unwrapped?.user?.userInfo;\n    const info = user?._value ?? user ?? {};\n    return toCleanString(info.user_id ?? info.userId ?? info.userID ?? '');\n}\n\nexport function mapCollectionNote(entry, options = {}) {\n    if (!isObject(entry))\n        return null;\n    const noteCard = entry.note_card ?? entry.noteCard ?? entry;\n    const noteId = toCleanString(entry.note_id\n        ?? entry.noteId\n        ?? entry.id","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/collection-helpers.js#L21-L57","documentation":"parseCollectionLimit validates the --limit CLI flag for xiaohongshu collection commands. It throws ArgumentError when the value parses to a finite integer but falls outside the allowed range of 1-100. The library enforces this cap because the xiaohongshu collection API's page size is bounded server-side.","triggerScenarios":"Calling a collection command with --limit 0, --limit 101, --limit -5, or any numeric value outside 1-100 (e.g. --limit 999). Values that are non-numeric or non-integer (like 'abc' or 2.5) throw the sibling integer-message error instead.","commonSituations":"Users guessing the valid range and trying 0 or 200; scripts templating a page size from config without clamping; automations passing an unbounded count collected elsewhere.","solutions":["Set --limit to a value between 1 and 100","Clamp the value in your script before invoking: Math.min(100, Math.max(1, n))","If you need more than 100 notes, rely on pagination of collection pages instead of one large limit"],"exampleFix":"// before\nconst { execSync } = require('child_process');\nexecSync(`xhs collection ${userId} --limit ${count}`); // count=250 -> throws\n// after\nconst safe = Math.min(100, Math.max(1, Number(count) || 20));\nexecSync(`xhs collection ${userId} --limit ${safe}`);","handlingStrategy":"validation","validationCode":"function safeLimit(raw) { const n = Number(raw ?? 20); return Number.isFinite(n) && Number.isInteger(n) && n >= 1 && n <= 100 ? n : 20; }","typeGuard":"const isValidLimit = (v) => Number.isFinite(Number(v)) && Number.isInteger(Number(v)) && Number(v) >= 1 && Number(v) <= 100;","tryCatchPattern":"try { const limit = parseCollectionLimit(raw); } catch (e) { if (e instanceof ArgumentError) { console.error(e.message); process.exitCode = 2; } else throw e; }","preventionTips":["Always clamp user-supplied limits into [1,100] before invoking the CLI","Default to the library default (20) when input is empty","Add integration tests covering boundary values 0, 1, 100, 101"],"tags":["cli","validation","argument-error","limit"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}