jackwener/OpenCLI · error · ArgumentError

--limit must be a positive integer in [1, ${HOT_LIMIT_MAX}],

Error message

--limit must be a positive integer in [1, ${HOT_LIMIT_MAX}], got ${JSON.stringify(raw)}

What it means

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.

Source

Thrown at clis/hupu/hot.js:42

//   - Pure extraction (`extractHupuHotRowsFromDoc`) is a Node-side export
//     so JSDOM-against-frozen-fixture tests can call it directly while the
//     live IIFE embeds the same function via `${fn.toString()}` (mirrors
//     dianping #1313 pattern).

import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';

export const HUPU_HOST = 'https://bbs.hupu.com';
export const HOT_LIMIT_DEFAULT = 20;
export const HOT_LIMIT_MAX = 100;

export function normalizeHotLimit(raw) {
    if (raw === undefined || raw === null || raw === '') {
        return HOT_LIMIT_DEFAULT;
    }
    const n = typeof raw === 'number' ? raw : Number(raw);
    if (!Number.isFinite(n) || !Number.isInteger(n) || n < 1 || n > HOT_LIMIT_MAX) {
        throw new ArgumentError(
            `--limit must be a positive integer in [1, ${HOT_LIMIT_MAX}], got ${JSON.stringify(raw)}`,
        );
    }
    return n;
}

// Parse hupu count strings like "50亮", "359回复", "1.2万" → typed int.
// Returns null when the input does not look like a count we can read.
// `0` is preserved (real value), `null` means "we could not extract it"
// — never use `0` as an unknown sentinel here.
export function parseHupuCount(raw) {
    if (raw === undefined || raw === null) return null;
    const text = String(raw).trim();
    if (!text) return null;
    const match = text.match(/^([0-9]+(?:\.[0-9]+)?)\s*(万)?/);
    if (!match) return null;
    const num = parseFloat(match[1]);
    if (!Number.isFinite(num)) return null;

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass an integer between 1 and HOT_LIMIT_MAX (see the constant in clis/hupu/hot.js), e.g. --limit 50
  2. Omit --limit entirely to use HOT_LIMIT_DEFAULT
  3. Clamp/parse the value in your own script before calling: Math.min(Math.max(1, n|0), HOT_LIMIT_MAX)
  4. Check the exact value being forwarded — the error message echoes the raw JSON of what was received

Example fix

// before
node cli hupu hot --limit 500
// after
node cli hupu hot --limit 100 // within [1, HOT_LIMIT_MAX]
// or programmatically
const limit = Math.min(Math.max(1, Math.trunc(Number(raw))), HOT_LIMIT_MAX);
Defensive patterns

Strategy: validation

Validate before calling

const HOT_LIMIT_MAX = 100; // match library constant
function validLimit(raw) {
  const n = Number(raw);
  return Number.isInteger(n) && n >= 1 && n <= HOT_LIMIT_MAX;
}
if (!validLimit(opts.limit)) opts.limit = HOT_LIMIT_DEFAULT;

Type guard

function isValidLimit(v) {
  return typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= HOT_LIMIT_MAX;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/ec90732b3d03e48e. Report an issue: GitHub.