{"record":{"id":"48dba0119a264dde","repo":"jackwener/OpenCLI","slug":"limit-must-be-between-1-and-50-got-parsed","errorCode":null,"errorMessage":"--limit must be between 1 and 50, got ${parsed}","messagePattern":"--limit must be between 1 and 50, got (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/rednote/comments.js","lineNumber":18,"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)' },\n        { name: 'with-replies', type: 'boolean', default: false, help: 'Include nested replies; reply_to is the direct target shown by the page' },\n    ],\n    columns: ['rank', 'author', 'text', 'likes', 'time', 'is_reply', 'reply_to', 'images'],","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/rednote/comments.js#L1-L36","documentation":"The second branch of parseCommentLimit: the value parsed as a finite integer but is outside the allowed range of 1–50, so the library throws ArgumentError with the parsed number. This guards both the API (page extraction cost) and row-count expectations; 0, negatives, and anything above 50 land here.","triggerScenarios":"--limit 0, --limit -5, or --limit 51+ on the rednote comments command; also --limit '' (Number('') === 0 → integer, range check fails) and --limit 999999.","commonSituations":"Scripts computing a limit from a count that turned out to be 0 (e.g. no results upstream); users assuming 'more is fine' and passing 100; copy-pasted configs from other tools with different maxima; shell variable defaulting to empty string, which parses as 0.","solutions":["Pass an integer in [1, 50]; omit --limit to use the default of 20.","Clamp the value before invoking: Math.min(50, Math.max(1, parsed)).","Fix upstream logic producing 0 or oversized counts instead of forwarding them as --limit.","If you genuinely need more comments, page through the command multiple times rather than raising --limit."],"exampleFix":"// before\nopencli rednote comments <note-url> --limit 100\n// after\nopencli rednote comments <note-url> --limit 50","handlingStrategy":"validation","validationCode":"function clampLimit(raw, min = 1, max = 50) {\n  const n = Math.round(Number(raw ?? 20));\n  if (!Number.isFinite(n)) return 20;\n  return Math.min(max, Math.max(min, n));\n}\nconst limit = clampLimit(opts.limit);","typeGuard":"function isValidLimit(v) {\n  return typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= 50;\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 between 1 and 50')) {\n    await run(['rednote', 'comments', noteUrl, '--limit', '50']); // clamp to max\n  } else throw err;\n}","preventionTips":["Clamp values into [1, 50] before calling; default to 20 when unsure.","Handle the 0-count upstream case explicitly instead of forwarding 0.","Don't assume other tools' maxima — this command caps at 50.","Treat '' as invalid: Number('') === 0 fails the range check.","Page through multiple calls if you need more than 50 comments."],"tags":["argument-validation","cli","rednote","limit-range"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}