jackwener/OpenCLI · error · ArgumentError

maxRounds must be a positive integer, got ${JSON.stringify(m

Error message

maxRounds must be a positive integer, got ${JSON.stringify(maxRounds)}

What it means

buildScrollHarvestJs validates maxRounds as a safe integer >= 1 (default 30 via options.maxRounds) and throws this ArgumentError otherwise. maxRounds bounds how many scroll/harvest rounds the injected script performs, preventing infinite scrolling against an ever-loading feed.

Source

Thrown at clis/xiaohongshu/search.js:631

export function buildSearchExtractJs(webHost) {
    return `
      (() => {
        const stripXhsAuthorDateSuffix = ${stripXhsAuthorDateSuffix.toString()};
        const extractSearchRows = ${extractSearchRows.toString()};
        return extractSearchRows(${JSON.stringify(webHost)});
      })()
    `;
}

export function buildScrollHarvestJs(webHost, targetCount, options = {}) {
    const maxRounds = options.maxRounds ?? 30;
    const budgetMs = options.budgetMs ?? 30_000;
    const step = options.step ?? DEFAULT_HARVEST_STEP;
    if (!Number.isSafeInteger(targetCount) || targetCount < 1) {
        throw new ArgumentError(`targetCount must be a positive integer, got ${JSON.stringify(targetCount)}`);
    }
    if (!Number.isSafeInteger(maxRounds) || maxRounds < 1) {
        throw new ArgumentError(`maxRounds must be a positive integer, got ${JSON.stringify(maxRounds)}`);
    }
    if (!Number.isFinite(budgetMs) || budgetMs <= 0) {
        throw new ArgumentError(`budgetMs must be a positive number, got ${JSON.stringify(budgetMs)}`);
    }
    if (!Number.isFinite(step) || step < 0) {
        throw new ArgumentError(`step must be a non-negative number, got ${JSON.stringify(step)}`);
    }
    return `
      (async () => {
        const targetCount = ${targetCount};
        const maxRounds = ${maxRounds};
        const budgetMs = ${budgetMs};
        const configuredStep = ${step};
        const webHost = ${JSON.stringify(webHost)};
        const noteUrlInfo = ${noteUrlInfo.toString()};
        const mergeHarvestedRow = ${mergeHarvestedRow.toString()};
        const stripXhsAuthorDateSuffix = ${stripXhsAuthorDateSuffix.toString()};
        const extractSearchRows = ${extractSearchRows.toString()};

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a positive safe integer in options, e.g. { maxRounds: 30 }.
  2. Omit options.maxRounds to use the default of 30.
  3. Validate config-derived values with Number.isSafeInteger before passing.
  4. Use budgetMs (time budget) rather than maxRounds: 0 to limit harvesting.

Example fix

// before
buildScrollHarvestJs(host, target, { maxRounds: config.rounds });
// after
const maxRounds = Number.isSafeInteger(config.rounds) && config.rounds >= 1
  ? config.rounds : 30;
buildScrollHarvestJs(host, target, { maxRounds });
Defensive patterns

Strategy: validation

Validate before calling

function assertMaxRounds(v) {
  if (!Number.isSafeInteger(v) || v < 1) {
    throw new TypeError(`maxRounds must be a positive safe integer, got ${JSON.stringify(v)}`);
  }
}
assertMaxRounds(options.maxRounds ?? 30);

Type guard

const isValidMaxRounds = (v) => v === undefined || (Number.isSafeInteger(v) && v >= 1);

Prevention

When it happens

Trigger: Passing options { maxRounds: 0 } (or negative/NaN/Infinity/float/string/undefined explicitly) to buildScrollHarvestJs.

Common situations: Config file supplying maxRounds: null; a caller that sets maxRounds from a computation that yields NaN; intending 0 to mean 'unlimited' but the API requires >= 1 and bounds come from budgetMs instead.

Related errors


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