{"record":{"id":"6988506e76b6be55","repo":"jackwener/OpenCLI","slug":"limit-must-be-an-integer-between-1-and-50-got","errorCode":null,"errorMessage":"--limit must be an integer between 1 and 50, got ${JSON.stringify(raw)}","messagePattern":"--limit must be an integer between 1 and 50, got (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/rednote/comments.js","lineNumber":15,"sourceCode":"/**\n * Rednote comments — international mirror of xiaohongshu/comments.\n * Reuses the DOM-extraction IIFE from `../xiaohongshu/comments.js`.\n */\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\nimport { buildCommentsExtractJs, normalizeCommentRows } from '../xiaohongshu/comments.js';\nimport { buildNoteUrl, parseNoteId } from '../xiaohongshu/note-helpers.js';\n\nconst REDNOTE_SIGNED_URL_HINT = 'Pass a full rednote.com note URL with xsec_token from search results or user/profile context.';\n\nfunction parseCommentLimit(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 50, got ${JSON.stringify(raw)}`);\n    }\n    if (parsed < 1 || parsed > 50) {\n        throw new ArgumentError(`--limit must be between 1 and 50, got ${parsed}`);\n    }\n    return parsed;\n}\n\ncli({\n    site: 'rednote',\n    name: 'comments',\n    access: 'read',\n    description: 'Read comments from a rednote note (supports nested replies)',\n    domain: 'www.rednote.com',\n    strategy: Strategy.COOKIE,\n    navigateBefore: false,\n    args: [\n        { name: 'note-id', required: true, positional: true, help: 'Full rednote note URL with xsec_token' },\n        { name: 'limit', type: 'int', default: 20, help: 'Number of top-level comments (max 50)' },","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/rednote/comments.js#L1-L33","documentation":"parseCommentLimit validates the --limit argument of the rednote comments command before any page work happens. The value must be a finite integer; Number(raw ?? 20) defaulting to 20 means null/undefined is fine, but non-numeric strings (NaN), floats, and other junk hit this ArgumentError with the raw value JSON-stringified for diagnosis.","triggerScenarios":"Calling the rednote comments command with --limit set to a non-integer or non-numeric value: e.g. --limit abc (NaN), --limit 10.5 (float), --limit '' (Number('') is 0 — actually passes this branch, fails range), --limit '20x', or a programmatic kwargs.limit of an object/array.","commonSituations":"Shell quoting mistakes passing '10.5' or 'all'; scripts interpolating an empty or malformed variable into --limit; CLI wrappers forwarding a string like 'null' or 'undefined'; fat-fingered values such as --limit 2.5.","solutions":["Pass an integer string, e.g. --limit 20 (omit the flag entirely to use the default of 20).","Check the variable being interpolated into --limit — an empty or malformed env/script variable is the usual culprit.","Strip units/whitespace before passing: --limit \"${COUNT%.*}\" if a float creeps in from a calculation.","Clamp programmatically before the call: Math.min(50, Math.max(1, Math.round(Number(raw))))."],"exampleFix":"// before\nopencli rednote comments <note-url> --limit 10.5\n// after\nopencli rednote comments <note-url> --limit 10","handlingStrategy":"validation","validationCode":"function validCommentLimit(raw) {\n  if (raw === undefined || raw === null) return true; // defaults to 20\n  const n = Number(raw);\n  return Number.isFinite(n) && Number.isInteger(n);\n}\nif (!validCommentLimit(opts.limit)) throw new Error(`--limit must be an integer, got ${JSON.stringify(opts.limit)}`);","typeGuard":"function isIntLimit(v) {\n  return typeof v === 'number' && Number.isInteger(v);\n}","tryCatchPattern":"try {\n  await run(['rednote', 'comments', noteUrl, '--limit', String(limit)]);\n} catch (err) {\n  if (err instanceof ArgumentError && err.message.includes('--limit must be an integer')) {\n    // fall back to default limit\n    await run(['rednote', 'comments', noteUrl]);\n  } else throw err;\n}","preventionTips":["Always pass --limit as a plain integer string; never interpolate raw user/env values unvalidated.","Omit --limit entirely to use the default of 20.","Sanitize inputs: Math.round(Number(x)) and check Number.isInteger before invoking.","Watch for shell quoting turning '10.5' or '20x' into the argument.","Validate upstream counters before forwarding them as --limit."],"tags":["argument-validation","cli","rednote","limit"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}