jackwener/OpenCLI · error · ArgumentError

${label} must be an integer >= ${min}, got ${JSON.stringify(

Error message

${label} must be an integer >= ${min}, got ${JSON.stringify(value)}

What it means

requireMinInt throws this ArgumentError when a CLI option expected to be an integer of at least `min` is missing, non-numeric, non-integer, or below the minimum. The offending raw value is included via JSON.stringify. It exists so bad user input fails fast with a clear message instead of producing a nonsense API request.

Source

Thrown at clis/stackoverflow/read.js:82

    }
    return json;
}

/**
 * CLI args may arrive as strings (`--limit 5` → `'5'`) when not coerced by the
 * arg type system. Coerce-then-validate so `Number.isInteger` actually catches
 * the bad cases, and reject NaN explicitly.
 */
function coerceInt(value) {
    if (value === undefined || value === null || value === '') return NaN;
    const n = typeof value === 'number' ? value : Number(value);
    return Number.isFinite(n) && Number.isInteger(n) ? n : NaN;
}

function requireMinInt(value, min, label) {
    const n = coerceInt(value);
    if (!Number.isInteger(n) || n < min) {
        throw new ArgumentError(`${label} must be an integer >= ${min}, got ${JSON.stringify(value)}`);
    }
    return n;
}

function requireBoundedInt(value, min, max, label) {
    const n = coerceInt(value);
    if (!Number.isInteger(n) || n < min || n > max) {
        throw new ArgumentError(`${label} must be an integer between ${min} and ${max}, got ${JSON.stringify(value)}`);
    }
    return n;
}

function byAcceptedThenScoreDesc(question, answers) {
    const acceptedAnswerId = question.accepted_answer_id;
    return answers
        .slice()
        .sort((a, b) => {
            const aAccepted = a.is_accepted || (acceptedAnswerId && a.answer_id === acceptedAnswerId);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass an integer >= 100 for --max-length, e.g. --max-length 4000
  2. Check the script/shell for unset variables yielding empty or 'NaN' values
  3. Quote or validate the value in wrapper scripts before invoking the CLI

Example fix

// before
stackoverflow read 79935770 --max-length 50
// after
stackoverflow read 79935770 --max-length 4000
Defensive patterns

Strategy: validation

Validate before calling

const n = Number(value);
if (!Number.isInteger(n) || n < 100) throw new Error(`max-length must be an integer >= 100, got ${value}`);

Type guard

function isIntAtLeast(value, min) {
  return typeof value === 'number' || typeof value === 'string'
    ? Number.isInteger(Number(value)) && Number(value) >= min
    : false;
}

Try / catch

try {
  await runCommand(['stackoverflow', 'read', id, '--max-length', String(len)]);
} catch (e) {
  if (e instanceof ArgumentError && e.message.includes('must be an integer >= 100')) {
    console.error('Fix --max-length: pass an integer >= 100');
  } else throw e;
}

Prevention

When it happens

Trigger: Running `stackoverflow read` with --max-length below 100, a non-integer like 12.5, a non-numeric string like 'abc', or empty/undefined so coerceInt yields NaN.

Common situations: Typo in the flag value (e.g. --max-length 50); shell passing an empty string for an unset flag; scripts interpolating an unset variable so the value arrives as '' or 'NaN'; copy-pasting a float like 1000.5.

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/cdc21d80c9798d65. Report an issue: GitHub.