{"record":{"id":"07c28d4f0a1100ca","repo":"jackwener/OpenCLI","slug":"limit-must-be-an-integer-between-1-and-100-got-07c28d","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/collection-helpers.js","lineNumber":36,"sourceCode":"function toCleanString(value) {\n    return typeof value === 'string' ? value.trim() : value == null ? '' : String(value).trim();\n}\n\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;","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/collection-helpers.js#L18-L54","documentation":"parseCollectionLimit validates the --limit option for Xiaohongshu collection commands. It throws ArgumentError when the value is not a finite integer (e.g. 'abc', '3.5', '[1,2]', objects) — the message echoes the raw JSON of what was passed. Range violations (outside 1–100) get a separate message.","triggerScenarios":"parseCollectionLimit(raw) receives NaN, a float, a numeric string with decimals, or a non-numeric value such that Number.isFinite(parsed) or Number.isInteger(parsed) fails; raw ?? 20 defaults undefined to 20.","commonSituations":"Passing --limit=abc or --limit=2.5 on the CLI; programmatically passing a string with whitespace/suffix like '20 notes'; an array/object from config files; forgetting the value ('--limit' alone) so the shell hands an odd token.","solutions":["Pass an integer between 1 and 100, e.g. --limit 20.","Coerce user input with Number() and Number.isInteger before calling the command.","Trim/strip non-numeric characters from strings prior to parsing.","Use the default by omitting --limit entirely (defaults to 20).","Validate CLI/config values at startup and fail fast with your own message."],"exampleFix":"// before\nawait cli.run(['xiaohongshu','collection','--limit', userLimit]); // userLimit = '2.5'\n// after\nconst n = Number(userLimit);\nif (!Number.isInteger(n) || n < 1 || n > 100) {\n  throw new Error(`--limit must be an integer 1-100, got ${userLimit}`);\n}\nawait cli.run(['xiaohongshu','collection','--limit', String(n)]);","handlingStrategy":"validation","validationCode":"function isValidLimit(v) {\n  const n = Number(v ?? 20);\n  return Number.isInteger(n) && n >= 1 && n <= 100;\n}\n// call only if isValidLimit(userLimit)","typeGuard":"function isIntLimit(v) {\n  return typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= 100;\n}","tryCatchPattern":"try {\n  return await collectionCommand({ limit: rawLimit });\n} catch (e) {\n  if (e instanceof ArgumentError && /--limit/.test(e.message)) {\n    return collectionCommand({ limit: 20 }); // fall back to default\n  }\n  throw e;\n}","preventionTips":["Always pass --limit as a plain integer string (e.g. '20', never '2.5' or '20 notes').","Validate user/config input with Number.isInteger before invoking commands.","Rely on the built-in default of 20 when unsure.","Sanitize strings (trim, strip units) before numeric coercion."],"tags":["validation","cli","argument-error","xiaohongshu"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}