jackwener/OpenCLI · warning · ArgumentError

bbc ${label} must be a positive integer

Error message

bbc ${label} must be a positive integer

What it means

ArgumentError from `requireBoundedInt` when the provided value is not an integer greater than 0 (NaN, float, string like 'abc', zero, or negative). The helper coerces to Number via `Number(raw)` and enforces integer positivity before checking the upper bound.

Source

Thrown at clis/bbc/utils.js:47

    let m;
    while ((m = re.exec(String(xml || ''))) !== null) {
        const block = m[1];
        out.push({
            title: decodeHtmlEntities(extractRssTag(block, 'title')).trim(),
            description: decodeHtmlEntities(extractRssTag(block, 'description')).trim(),
            link: decodeHtmlEntities(extractRssTag(block, 'link')).trim(),
            pubDate: decodeHtmlEntities(extractRssTag(block, 'pubDate')).trim(),
            guid: decodeHtmlEntities(extractRssTag(block, 'guid')).trim(),
        });
    }
    return out;
}

export function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {
    const raw = value ?? defaultValue;
    const n = typeof raw === 'number' ? raw : Number(raw);
    if (!Number.isInteger(n) || n <= 0) {
        throw new ArgumentError(`bbc ${label} must be a positive integer`);
    }
    if (n > maxValue) {
        throw new ArgumentError(`bbc ${label} must be <= ${maxValue}`);
    }
    return n;
}

export async function bbcFetchRss(path, label) {
    const url = `${BBC_FEED_BASE}/${path}`;
    let resp;
    try {
        resp = await fetch(url, { headers: { 'user-agent': UA, accept: 'application/rss+xml, application/xml' } });
    }
    catch (err) {
        throw new CommandExecutionError(
            `${label} request failed: ${err?.message ?? err}`,
            'Check that feeds.bbci.co.uk is reachable from this network.',
        );

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a positive integer, e.g. `--limit 20`.
  2. Strip units/whitespace before passing numeric arguments.
  3. Validate the argument in your script with Number.isInteger before calling the CLI.
  4. Omit the flag to use the default (20).

Example fix

// before
await cli.run(['bbc','topic','technology','--limit','abc']);
// after
await cli.run(['bbc','topic','technology','--limit','20']);
Defensive patterns

Strategy: validation

Validate before calling

function assertLimit(v){ const n = Number(v); if (!Number.isInteger(n) || n <= 0) throw new Error('limit must be a positive integer'); return n; }

Type guard

const isPositiveInt = (v) => Number.isInteger(Number(v)) && Number(v) > 0 && String(v).trim() !== '';

Try / catch

try {
  const items = await cli.run(['bbc','topic', topic, '--limit', String(limit)]);
} catch (e) {
  if (e.name === 'ArgumentError' && /positive integer/.test(e.message)) {
    limit = 20; // fall back to default and retry
  }
}

Prevention

When it happens

Trigger: `bbc topic --limit 0`, `--limit -5`, `--limit abc`, `--limit 2.5`, or any non-numeric string that fails `Number.isInteger(Number(raw))`.

Common situations: Typos in CLI flags, passing default/placeholder text instead of a number, copy-pasting values with units ('20 items'), scripts passing undefined wrapped as the string 'undefined'.

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