{"record":{"id":"53bf1e11e2b6b6e5","repo":"jackwener/OpenCLI","slug":"limit-must-be-a-positive-integer-got-parsed-53bf1e","errorCode":null,"errorMessage":"--limit must be a positive integer, got ${parsed}","messagePattern":"--limit must be a positive integer, got (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/rednote/user.js","lineNumber":14,"sourceCode":"import { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, EmptyResultError } from '@jackwener/opencli/errors';\nimport { USER_SNAPSHOT_JS } from '../xiaohongshu/user.js';\nimport { extractXhsUserNotes, normalizeXhsUserId } from '../xiaohongshu/user-helpers.js';\n\nconst WEB_HOST = 'www.rednote.com';\n\nfunction parseLimit(raw) {\n    const parsed = Number(raw ?? 15);\n    if (!Number.isFinite(parsed) || !Number.isInteger(parsed)) {\n        throw new ArgumentError(`--limit must be a positive integer, got ${JSON.stringify(raw)}`);\n    }\n    if (parsed < 1) {\n        throw new ArgumentError(`--limit must be a positive integer, got ${parsed}`);\n    }\n    return parsed;\n}\n\nexport const command = cli({\n    site: 'rednote',\n    name: 'user',\n    access: 'read',\n    description: 'Get public notes from a rednote user profile',\n    domain: WEB_HOST,\n    strategy: Strategy.COOKIE,\n    browser: true,\n    navigateBefore: false,\n    args: [\n        { name: 'id', type: 'str', required: true, positional: true, help: 'User id or profile URL' },\n        { name: 'limit', type: 'int', default: 15, help: 'Number of notes to return' },\n    ],\n    columns: ['id', 'title', 'type', 'likes', 'url'],","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/rednote/user.js#L1-L32","documentation":"parseLimit for the rednote user command throws ArgumentError when the value is a valid integer but less than 1 (0 or negative). Unlike notifications (default 20), this parser defaults to 15 when the option is omitted; an explicit out-of-range integer still fails here.","triggerScenarios":"Passing --limit 0 or a negative number (e.g. --limit -3) to the rednote user command. String '0' also coerces to 0 and triggers this branch.","commonSituations":"Scripts computing a remaining-count that reached 0 and still calling the command, users expecting 0 to mean 'no limit' or 'skip', template variables defaulting to 0.","solutions":["Pass --limit >= 1 or omit the flag to use the default of 15","Clamp before invoking: Math.max(1, n)","Fix generating scripts to skip the call entirely when the computed count is 0"],"exampleFix":"// before\nconst remaining = quota - used; // may be 0\nrun(['rednote','user','--id',id,'--limit',remaining]);\n// after\nconst remaining = Math.max(1, quota - used);\nrun(['rednote','user','--id',id,'--limit',remaining]);","handlingStrategy":"validation","validationCode":"const n = Number(raw ?? 15); if (Number.isInteger(n) && n < 1) throw new Error(`--limit must be >= 1, got ${n}`);","typeGuard":"const isPositiveUserLimit = (v) => Number.isInteger(v) && v >= 1;","tryCatchPattern":"try { await runUser({ id, limit }); } catch (e) { if (e instanceof ArgumentError && /positive integer/.test(e.message)) { return runUser({ id, limit: Math.max(1, limit) }); } throw e; }","preventionTips":["Skip the call outright when a computed count is 0 instead of passing 0","Clamp with Math.max(1, n) in wrapper scripts","Treat 0/negative limits as 'use default' rather than 'none'"],"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"}