jackwener/OpenCLI · error · ArgumentError

expand-rounds must be an integer in [${REDDIT_EXPAND_ROUNDS_

Error message

expand-rounds must be an integer in [${REDDIT_EXPAND_ROUNDS_MIN}, ${REDDIT_EXPAND_ROUNDS_MAX}].

What it means

parseExpandRounds validates the --expand-rounds option, which caps how many passes of /api/morechildren.json expansion are run. The value must be a finite integer within [REDDIT_EXPAND_ROUNDS_MIN, REDDIT_EXPAND_ROUNDS_MAX] = [1, 5]. Non-numeric, non-integer, out-of-range, NaN or Infinity inputs raise this ArgumentError with the offending value echoed back.

Source

Thrown at clis/reddit/read.js:92

    if (raw.includes('/') || raw.startsWith('t1_')) {
        throw new ArgumentError(
            'Post ID must be a Reddit post id, t3_ fullname, or reddit.com post URL.',
            'Use a bare post id like 1abc123, a fullname like t3_1abc123, or a full Reddit post URL.',
        );
    }

    return normalizeBareRedditPostId(raw);
}

export function parseExpandRounds(raw) {
    if (raw === undefined || raw === null || raw === '') return DEFAULT_EXPAND_ROUNDS;
    const n = Number(raw);
    if (
        !Number.isFinite(n) || !Number.isInteger(n)
        || n < REDDIT_EXPAND_ROUNDS_MIN || n > REDDIT_EXPAND_ROUNDS_MAX
    ) {
        throw new ArgumentError(
            `expand-rounds must be an integer in [${REDDIT_EXPAND_ROUNDS_MIN}, ${REDDIT_EXPAND_ROUNDS_MAX}].`,
            `Got: ${raw}`,
        );
    }
    return n;
}

cli({
    site: 'reddit',
    name: 'read',
    access: 'read',
    description: 'Read a Reddit post and its comments',
    domain: 'reddit.com',
    strategy: Strategy.COOKIE,
    browser: true,
    args: [
        { name: 'post-id', required: true, positional: true, help: 'Post ID (e.g. 1abc123) or full URL' },
        { name: 'sort', default: 'best', help: 'Comment sort: best, top, new, controversial, old, qa' },

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Set --expand-rounds to an integer between 1 and 5 (default is 2 when omitted).
  2. If the value comes from a variable/env var, coerce and clamp it before passing, e.g. Math.min(5, Math.max(1, Math.round(Number(v)))).
  3. Omit the flag entirely to use the default of 2.

Example fix

// before
reddit read 1abc123 --expand-rounds 10
// after
reddit read 1abc123 --expand-rounds 5
Defensive patterns

Strategy: validation

Validate before calling

function clampExpandRounds(v, min = 1, max = 5, dflt = 2) {
  if (v === undefined || v === null || v === '') return dflt;
  const n = Number(v);
  if (!Number.isInteger(n) || n < min || n > max) throw new Error(`expand-rounds must be int in [${min},${max}], got ${v}`);
  return n;
}

Type guard

const isValidExpandRounds = (v) =>
  v === undefined || v === null || v === '' ||
  (Number.isInteger(Number(v)) && Number(v) >= 1 && Number(v) <= 5);

Try / catch

try {
  await redditRead(id, { expandRounds: rawRounds });
} catch (e) {
  if (/expand-rounds must be an integer/.test(e.message)) {
    console.warn('Bad --expand-rounds, using default 2');
    await redditRead(id, { expandRounds: 2 });
  } else throw e;
}

Prevention

When it happens

Trigger: Passing --expand-rounds 0, 6, 2.5, 'many', or an empty-ish value that Number() coerces to NaN (only undefined/null/'' fall back to the default of 2).

Common situations: Typo in a script flag (e.g. --expand-rounds=-1); copying a fractional default like 1.5 from a config; environment-variable substitution producing an empty or garbage string that is not exactly ''.

Related errors


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