{"record":{"id":"ec90732b3d03e48e","repo":"jackwener/OpenCLI","slug":"limit-must-be-a-positive-integer-in-1-hot-li","errorCode":null,"errorMessage":"--limit must be a positive integer in [1, ${HOT_LIMIT_MAX}], got ${JSON.stringify(raw)}","messagePattern":"--limit must be a positive integer in \\[1, (.+?)\\], got (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/hupu/hot.js","lineNumber":42,"sourceCode":"//   - Pure extraction (`extractHupuHotRowsFromDoc`) is a Node-side export\n//     so JSDOM-against-frozen-fixture tests can call it directly while the\n//     live IIFE embeds the same function via `${fn.toString()}` (mirrors\n//     dianping #1313 pattern).\n\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\n\nexport const HUPU_HOST = 'https://bbs.hupu.com';\nexport const HOT_LIMIT_DEFAULT = 20;\nexport const HOT_LIMIT_MAX = 100;\n\nexport function normalizeHotLimit(raw) {\n    if (raw === undefined || raw === null || raw === '') {\n        return HOT_LIMIT_DEFAULT;\n    }\n    const n = typeof raw === 'number' ? raw : Number(raw);\n    if (!Number.isFinite(n) || !Number.isInteger(n) || n < 1 || n > HOT_LIMIT_MAX) {\n        throw new ArgumentError(\n            `--limit must be a positive integer in [1, ${HOT_LIMIT_MAX}], got ${JSON.stringify(raw)}`,\n        );\n    }\n    return n;\n}\n\n// Parse hupu count strings like \"50亮\", \"359回复\", \"1.2万\" → typed int.\n// Returns null when the input does not look like a count we can read.\n// `0` is preserved (real value), `null` means \"we could not extract it\"\n// — never use `0` as an unknown sentinel here.\nexport function parseHupuCount(raw) {\n    if (raw === undefined || raw === null) return null;\n    const text = String(raw).trim();\n    if (!text) return null;\n    const match = text.match(/^([0-9]+(?:\\.[0-9]+)?)\\s*(万)?/);\n    if (!match) return null;\n    const num = parseFloat(match[1]);\n    if (!Number.isFinite(num)) return null;","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hupu/hot.js#L24-L60","documentation":"normalizeHotLimit validates the --limit option for the hupu hot command against HOT_LIMIT_MAX. Values that are not finite integers within [1, HOT_LIMIT_MAX] (including non-numeric strings and out-of-range numbers) raise this ArgumentError instead of being silently clamped.","triggerScenarios":"Calling hupu hot with --limit set to 0, a negative number, a value above HOT_LIMIT_MAX, a float, or a non-numeric string like 'abc' (via CLI flag or programmatic limit option).","commonSituations":"Typo in the CLI flag value; scripts passing a padded/whitespace string; assuming the library clamps instead of validating; copy-pasting a limit from another tool with a different maximum.","solutions":["Pass an integer between 1 and HOT_LIMIT_MAX (see the constant in clis/hupu/hot.js), e.g. --limit 50","Omit --limit entirely to use HOT_LIMIT_DEFAULT","Clamp/parse the value in your own script before calling: Math.min(Math.max(1, n|0), HOT_LIMIT_MAX)","Check the exact value being forwarded — the error message echoes the raw JSON of what was received"],"exampleFix":"// before\nnode cli hupu hot --limit 500\n// after\nnode cli hupu hot --limit 100 // within [1, HOT_LIMIT_MAX]\n// or programmatically\nconst limit = Math.min(Math.max(1, Math.trunc(Number(raw))), HOT_LIMIT_MAX);","handlingStrategy":"validation","validationCode":"const HOT_LIMIT_MAX = 100; // match library constant\nfunction validLimit(raw) {\n  const n = Number(raw);\n  return Number.isInteger(n) && n >= 1 && n <= HOT_LIMIT_MAX;\n}\nif (!validLimit(opts.limit)) opts.limit = HOT_LIMIT_DEFAULT;","typeGuard":"function isValidLimit(v) {\n  return typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= HOT_LIMIT_MAX;\n}","tryCatchPattern":null,"preventionTips":["Omit --limit to use the default when unsure of the maximum","Clamp user input with Math.min/Math.max before passing","Never pass string limits from scripts without Number() coercion","Check HOT_LIMIT_MAX in clis/hupu/hot.js when configuring"],"tags":["validation","argument-error","cli","hupu"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}