jackwener/OpenCLI · error · ArgumentError

${label} must be an integer >= ${min}

Error message

${label} must be an integer >= ${min}

What it means

Thrown by requireMinInt in clis/lobsters/read.js:40 when --max-length is not an integer or is below the minimum of 100. This flag caps the characters per comment/story body; the library enforces a floor so truncation logic and output formatting behave predictably.

Source

Thrown at clis/lobsters/read.js:40

    if (res.status === 404) {
        throw new EmptyResultError(`lobsters/${shortId}`, 'Story not found');
    }
    if (!res.ok) {
        throw new CommandExecutionError(`Lobsters API HTTP ${res.status} for story ${shortId}`, 'Check the short id');
    }
    return res.json();
}

function requirePositiveInt(value, label) {
    if (!Number.isInteger(value) || value <= 0) {
        throw new ArgumentError(`${label} must be a positive integer`);
    }
    return value;
}

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

/** Lobsters returns comment text as a small HTML subset — convert to plain text. */
function htmlToText(html) {
    if (!html) return '';
    return String(html)
        .replace(/<p>/gi, '\n\n')
        .replace(/<\/p>/gi, '')
        .replace(/<br\s*\/?>/gi, '\n')
        .replace(/<i>(.*?)<\/i>/gi, '$1')
        .replace(/<em>(.*?)<\/em>/gi, '$1')
        .replace(/<strong>(.*?)<\/strong>/gi, '$1')
        .replace(/<a[^>]*href="([^"]*)"[^>]*>(.*?)<\/a>/gi, '$2 ($1)')
        .replace(/<pre><code>([\s\S]*?)<\/code><\/pre>/gi, '\n$1\n')
        .replace(/<code>(.*?)<\/code>/gi, '`$1`')
        .replace(/<[^>]+>/g, '')

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass an integer of at least 100, e.g. `lobsters read 6cmh6h --max-length 500`
  2. Omit the flag to use the default of 2000
  3. Clamp values in calling code: Math.max(100, Math.floor(n)) before passing
  4. For short output, post-truncate results yourself instead of setting max-length below 100

Example fix

// before
lobsters read 6cmh6h --max-length 50
// after
lobsters read 6cmh6h --max-length 100
Defensive patterns

Strategy: validation

Validate before calling

function assertMaxLength(v) {
  if (!Number.isInteger(v) || v < 100) throw new Error('--max-length must be an integer >= 100');
}
assertMaxLength(maxLength);

Type guard

function isValidMaxLength(v) {
  return Number.isInteger(v) && v >= 100;
}

Try / catch

try {
  await run(['lobsters', 'read', id, '--max-length', String(maxLength)]);
} catch (e) {
  if (e.message.includes('must be an integer >= ')) {
    maxLength = Math.max(100, Math.floor(Number(maxLength)));
    return run(['lobsters', 'read', id, '--max-length', String(maxLength)]);
  }
  throw e;
}

Prevention

When it happens

Trigger: Passing `--max-length 50`, `--max-length 0`, `--max-length -1`, or a non-integer like `--max-length 99.9` raises ArgumentError with 'must be an integer >= 100'.

Common situations: Trying to get ultra-compact output by setting a tiny max-length; scripting the flag from a config with an unset/zero value; typos like 10o0 that fail int parsing.

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