jackwener/OpenCLI · error · ArgumentError

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

Error message

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

What it means

`requireMinInt` throws `ArgumentError` when a value is not an integer or falls below a configured minimum. For `hackernews read`, it enforces `--max-length >= 100`, ensuring comment bodies are never truncated below a usable size. It is thrown before any HN API request is made.

Source

Thrown at clis/hackernews/read.js:35

async function fetchItem(id) {
    const res = await fetch(`${HN_ITEM_BASE}/${id}.json`);
    if (!res.ok) {
        throw new CommandExecutionError(`HN API HTTP ${res.status} for item ${id}`, 'Check the item 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;
}

/** HN stores 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(/<a[^>]*href="([^"]*)"[^>]*>(.*?)<\/a>/gi, '$2 ($1)')
        .replace(/<pre><code>([\s\S]*?)<\/code><\/pre>/gi, '\n$1\n')
        .replace(/<[^>]+>/g, '')
        .replace(/&#x27;/g, "'")
        .replace(/&quot;/g, '"')
        .replace(/&lt;/g, '<')

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Set `--max-length` to an integer >= 100 (default is 2000)
  2. Omit the flag to use the default of 2000 characters per comment body
  3. If truncation to less than 100 chars is desired, post-process the output instead (e.g. pipe through `cut`/`head`)

Example fix

// before
opencli hackernews read 39847301 --max-length 80
// after
opencli hackernews read 39847301 --max-length 100
Defensive patterns

Strategy: validation

Validate before calling

const v = Number(process.env.HN_MAX_LENGTH ?? 2000);
if (!Number.isInteger(v) || v < 100) {
  throw new Error(`--max-length must be an integer >= 100, got: ${process.env.HN_MAX_LENGTH}`);
}

Type guard

function isIntAtLeast(v, min) {
  return typeof v === 'number' && Number.isInteger(v) && v >= min;
}

Try / catch

try {
  await run(['opencli', 'hackernews', 'read', id, '--max-length', String(ml)]);
} catch (e) {
  if (String(e.message).includes('must be an integer >=')) {
    console.error('max-length below minimum 100; falling back to 2000');
    await run(['opencli', 'hackernews', 'read', id]);
  } else throw e;
}

Prevention

When it happens

Trigger: Running `hackernews read <id> --max-length 50` (or any value < 100), a non-integer like `--max-length 99.5`, or a non-numeric value; `--max-length` sourced from an unset/empty shell variable parsed as invalid.

Common situations: Users trying to get very short comment snippets with `--max-length 0` or small values; config files with `max_length: 50` that predate the min-100 rule; scripts passing defaults of empty string.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


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