{"record":{"id":"4620524e55886dc9","repo":"jackwener/OpenCLI","slug":"limit-must-be-a-positive-integer-got-json-str-462052","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/notifications.js","lineNumber":28,"sourceCode":" * `feed` hits on rednote.\n */\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, CommandExecutionError } from '@jackwener/opencli/errors';\n\nconst NOTIFICATION_TYPES = new Set(['mentions', 'likes', 'connections']);\n\nfunction parseNotificationType(raw) {\n    const type = String(raw ?? 'mentions');\n    if (!NOTIFICATION_TYPES.has(type)) {\n        throw new ArgumentError(`--type must be one of mentions, likes, or connections, got ${JSON.stringify(raw)}`);\n    }\n    return type;\n}\n\nfunction parseLimit(raw) {\n    const parsed = Number(raw ?? 20);\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\nconst READ_NOTIFICATIONS_JS = `\n  (async (type) => {\n    let pinia = null;\n    const probe = (el) => el?.__vue_app__?.config?.globalProperties?.$pinia ?? null;\n    pinia = probe(document.querySelector('#app'));\n    if (!pinia) {\n      for (const el of document.querySelectorAll('*')) {\n        pinia = probe(el);\n        if (pinia) break;\n      }\n    }","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/rednote/notifications.js#L10-L46","documentation":"parseLimit normalizes the --limit CLI option into a finite integer (defaulting to 20). It throws ArgumentError when the raw value cannot be coerced by Number() into a finite integer, e.g. strings like 'abc', '3.5', 'null', or ''. This fail-fast guard prevents downstream pagination code from receiving a nonsensical limit.","triggerScenarios":"Calling the rednote notifications command with --limit set to a non-numeric string ('abc'), a float ('2.5'), an empty string, or a value that JSON.stringify reveals as undefined/null passed explicitly.","commonSituations":"Typo in the flag value, shell variable interpolation producing an empty or quoted string (--limit \"$MYVAR\" where MYVAR is unset), scripting that forwards unvalidated user input, or pasting '20 notes' instead of 20.","solutions":["Pass a plain positive integer, e.g. --limit 20","If the flag comes from a shell variable, default it before use: LIMIT=${LIMIT:-20}","Validate with Number.isInteger(Number(value)) before invoking the command"],"exampleFix":"// before\nnode cli.js rednote notifications --limit \"$LIMIT\"\n// after\nconst LIMIT = Number.isInteger(Number(process.env.LIMIT)) ? Number(process.env.LIMIT) : 20;\nnode cli.js rednote notifications --limit ${LIMIT}","handlingStrategy":"validation","validationCode":"function assertLimit(raw){ const n = Number(raw ?? 20); if (!Number.isFinite(n) || !Number.isInteger(n)) throw new Error(`--limit must be a positive integer, got ${JSON.stringify(raw)}`); return n; }","typeGuard":"const isValidLimit = (v) => Number.isFinite(Number(v)) && Number.isInteger(Number(v));","tryCatchPattern":"try { await runNotifications({ limit }); } catch (e) { if (e instanceof ArgumentError && /--limit/.test(e.message)) { console.error('Fix --limit:', e.message); process.exitCode = 2; } else throw e; }","preventionTips":["Always pass --limit as an unquoted plain integer in shell commands","Default shell variables before interpolation: LIMIT=${LIMIT:-20}","Unit-test CLI wrappers with the raw values users are likely to pass"],"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"}