{"record":{"id":"0cc90976c5052bfe","repo":"jackwener/OpenCLI","slug":"limit-must-be-a-positive-integer-got-json-str-0cc909","errorCode":null,"errorMessage":"--limit must be a positive integer, got ${JSON.stringify(raw)}","messagePattern":"--limit must be a positive integer, got (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/rednote/user.js","lineNumber":11,"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' },","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/rednote/user.js#L1-L29","documentation":"The rednote user command's parseLimit defaults to 15 and throws ArgumentError when --limit cannot be coerced into a finite integer (non-numeric strings, floats, empty values). The raw input is echoed via JSON.stringify to make the offending value obvious.","triggerScenarios":"Calling the rednote user command with --limit 'abc', --limit '2.5', --limit '', or an unset variable interpolated to empty string (Number('') is 0, but Number(' ') or 'abc' fail here).","commonSituations":"Shell variables that are unset or contain whitespace/units ('15 users'), config files exporting limit as text with stray characters, or typos like --limit l5.","solutions":["Pass a plain positive integer, e.g. --limit 15","Trim/validate interpolated shell values before passing them","Rely on the built-in default by omitting --limit entirely"],"exampleFix":"// before\nnode cli.js rednote user --id \"$UID_ARG\" --limit \"$LIMIT\"\n// after\nLIMIT=${LIMIT:-15}; LIMIT=$(echo \"$LIMIT\" | tr -d '[:space:]')\nnode cli.js rednote user --id \"$UID_ARG\" --limit \"$LIMIT\"","handlingStrategy":"validation","validationCode":"function assertUserLimit(raw){ const n = Number(raw ?? 15); if (!Number.isFinite(n) || !Number.isInteger(n)) throw new Error(`--limit must be a positive integer, got ${JSON.stringify(raw)}`); return n; }","typeGuard":"const isValidUserLimit = (v) => v === undefined || (Number.isInteger(Number(v)) && Number.isFinite(Number(v)));","tryCatchPattern":"try { await runUser({ id, limit }); } catch (e) { if (e instanceof ArgumentError && /--limit/.test(e.message)) { console.error('Pass an integer --limit or omit for default 15'); process.exitCode = 2; return; } throw e; }","preventionTips":["Omit --limit to use the built-in default of 15","Sanitize shell-interpolated values (trim whitespace, strip units)","Validate with Number.isInteger before invoking"],"tags":["cli","argument-validation","input"],"backgroundTag":"invalid-cli-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}