jackwener/OpenCLI · error · ArgumentError

lobsters limit must be a positive integer

Error message

lobsters limit must be a positive integer

What it means

Thrown by requireBoundedInt() when the limit value (or its Number() coercion) is not an integer or is <= 0. The lobsters limit option must be a positive whole number used to cap the number of fetched stories.

Source

Thrown at clis/lobsters/domain.js:27

const DOMAIN_PATTERN = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)+$/i;

function requireDomain(value) {
    const s = String(value ?? '').trim().toLowerCase();
    if (!s) {
        throw new ArgumentError('lobsters domain is required (e.g. "github.com" or "arxiv.org")');
    }
    if (!DOMAIN_PATTERN.test(s)) {
        throw new ArgumentError(`lobsters domain "${value}" is not a valid hostname`);
    }
    return s;
}

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

cli({
    site: 'lobsters',
    name: 'domain',
    access: 'read',
    description: 'Lobste.rs stories submitted from a specific domain',
    domain: 'lobste.rs',
    strategy: Strategy.PUBLIC,
    browser: false,
    args: [
        { name: 'domain', positional: true, required: true, help: 'Source domain (e.g. github.com, arxiv.org, blog.cloudflare.com)' },
        { name: 'limit', type: 'int', default: 20, help: 'Number of stories (1-25 — single page)' },

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a positive integer, e.g. limit(25) or `--limit 25`
  2. Omit the option to fall back to the configured defaultValue
  3. Parse and sanitize user input with Number.parseInt and validate Number.isInteger(n) && n > 0 first
  4. Replace 'unlimited'/0-style requests with a large finite value within the allowed max

Example fix

// before
await cli.limit(opts.limit); // opts.limit === '0'
// after
const n = Number.parseInt(opts.limit, 10);
await cli.limit(Number.isInteger(n) && n > 0 ? n : undefined);
Defensive patterns

Strategy: validation

Validate before calling

function toPositiveInt(v, fallback) {
  if (v == null) return fallback;
  const n = typeof v === 'number' ? v : Number(v);
  return Number.isInteger(n) && n > 0 ? n : fallback;
}
await cli.limit(toPositiveInt(opts.limit, 25));

Type guard

function isPositiveInt(v) {
  return typeof v === 'number' && Number.isInteger(v) && v > 0;
}

Try / catch

try {
  await cli.limit(rawLimit);
} catch (err) {
  if (err instanceof ArgumentError && /limit must be a positive integer/.test(err.message)) {
    console.error(`--limit must be a positive whole number, got: ${rawLimit}`);
    process.exitCode = 2;
  } else throw err;
}

Prevention

When it happens

Trigger: Calling limit() with undefined when no defaultValue was provided, NaN, 'abc', 0, -5, 2.5, or a non-numeric string like 'ten'.

Common situations: CLI flag parsed from a string flag that was omitted (empty string coerces to NaN); users pass '0' expecting 'unlimited'; decimal input like '10.5'; locale-formatted numbers with commas ('1,000' coerces to NaN).

Related errors


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