jackwener/OpenCLI · error · ArgumentError

${label} must be <= ${maxValue}

Error message

${label} must be <= ${maxValue}

What it means

ArgumentError from normalizeLimit when the limit is a valid positive integer but exceeds the command's maxValue (e.g. 100 for related/tag). The Stack Exchange API caps pagesize, so the CLI enforces the cap up front instead of letting the API reject or silently truncate.

Source

Thrown at clis/stackoverflow/utils.js:26

    ArgumentError,
    CommandExecutionError,
    EmptyResultError,
} from '@jackwener/opencli/errors';

export const SE_API = 'https://api.stackexchange.com/2.3';
export const SE_SITE = 'stackoverflow';

const UA = 'opencli-stackoverflow (+https://github.com/jackwener/opencli)';

/** Validate `limit` per typed-fail-fast convention (no silent clamp). */
export function normalizeLimit(value, defaultValue, maxValue, label = 'limit') {
    const raw = value ?? defaultValue;
    const limit = Number(raw);
    if (!Number.isInteger(limit) || limit <= 0) {
        throw new ArgumentError(`${label} must be a positive integer`);
    }
    if (limit > maxValue) {
        throw new ArgumentError(`${label} must be <= ${maxValue}`);
    }
    return limit;
}

export function requireString(value, label) {
    const raw = String(value ?? '').trim();
    if (!raw) {
        throw new ArgumentError(`${label} cannot be empty`);
    }
    return raw;
}

/** Fetch a Stack Exchange API endpoint and return parsed JSON envelope. */
export async function seFetch(path, { searchParams } = {}) {
    const url = new URL(path.startsWith('http') ? path : `${SE_API}${path.startsWith('/') ? '' : '/'}${path}`);
    if (searchParams) {
        for (const [k, v] of Object.entries(searchParams)) {
            if (v == null || v === '') continue;

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Lower --limit to <= the stated max (100 for these commands).
  2. Paginate by varying the `page` parameter across multiple calls of <=100 each if you need more results.
  3. Clamp in your own script before invoking: const capped = Math.min(limit, 100).

Example fix

// before
stackoverflow related 79935770 --limit 500
// after
stackoverflow related 79935770 --limit 100
Defensive patterns

Strategy: validation

Validate before calling

function capLimit(v, max = 100) {
  const n = Number(v);
  if (!Number.isInteger(n) || n <= 0 || n > max) throw new TypeError(`limit must be an integer in 1..${max}`);
  return n;
}

Type guard

function isBoundedLimit(v, max = 100) { return Number.isInteger(v) && v > 0 && v <= max; }

Try / catch

try {
  return await run({ limit });
} catch (e) {
  if (e.name === 'ArgumentError' && /must be <= \d+/.test(e.message)) {
    return run({ limit: 100 }); // clamp to the documented max
  }
  throw e;
}

Prevention

When it happens

Trigger: `stackoverflow related <id> --limit 500` or `stackoverflow tag <tag> --limit 101`; a script building pagesize from an unbounded config value.

Common situations: Trying to bulk-download many results in one call; a config value tuned for a different tool with a higher cap; misunderstanding that the cap is per-request, not overall.

Related errors


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