jackwener/OpenCLI · error · ArgumentError

medium limit must be a positive integer

Error message

medium limit must be a positive integer

What it means

The medium tag command's --limit option is normalized by requireBoundedInt, which coerces the raw value to a number and requires it to be a positive integer before checking the upper bound. ArgumentError is thrown when the value is not an integer or is <= 0 (non-numeric strings, decimals, zero, negatives, NaN).

Source

Thrown at clis/medium/tag.js:69

function requireTag(value) {
    const s = String(value ?? '').trim().toLowerCase();
    if (!s) {
        throw new ArgumentError('medium tag is required (e.g. "programming", "javascript")');
    }
    if (!TAG_PATTERN.test(s)) {
        throw new ArgumentError(
            `medium tag "${value}" is not valid`,
            'Tags are lowercase alphanumeric, optionally hyphenated (e.g. "machine-learning").',
        );
    }
    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('medium limit must be a positive integer');
    }
    if (n > maxValue) {
        throw new ArgumentError(`medium limit must be <= ${maxValue}`);
    }
    return n;
}

cli({
    site: 'medium',
    name: 'tag',
    access: 'read',
    description: 'Latest Medium articles tagged with a given keyword (RSS feed)',
    domain: 'medium.com',
    strategy: Strategy.PUBLIC,
    browser: false,
    args: [
        { name: 'tag', positional: true, required: true, help: 'Lowercase tag slug (e.g. "programming", "machine-learning")' },
        { name: 'limit', type: 'int', default: 20, help: 'Max articles (1-25 — single RSS page)' },

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a positive whole number, e.g. `medium tag programming --limit 10`.
  2. Omit --limit entirely to use the default value handled by requireBoundedInt.
  3. If building the value in a script, coerce with Math.floor(Number(value)) and validate Number.isInteger(n) && n > 0 before calling.
  4. Check the command's maxValue from the cli() definition to also stay within the upper bound.

Example fix

// before
medium tag programming --limit all
// after
medium tag programming --limit 10
Defensive patterns

Strategy: validation

Validate before calling

const n = Number(limit);
if (!Number.isInteger(n) || n <= 0) throw new Error('--limit must be a positive integer');

Type guard

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

Try / catch

try {
  await run(['medium', 'tag', tag, '--limit', String(limit)]);
} catch (e) {
  if (e instanceof ArgumentError && /limit must be a positive integer/.test(e.message)) {
    console.error('Use a whole number > 0, e.g. --limit 10');
  } else throw e;
}

Prevention

When it happens

Trigger: Running `medium tag <tag> --limit 0`, a negative value like `--limit -3`, a decimal like `--limit 2.5`, or a non-numeric string like `--limit all` or `--limit 10x`.

Common situations: Passing 'all' or 'max' expecting a sentinel; typo'd flag values; locale-formatted numbers ('1,000'); forgetting the flag belongs to another command so a word lands in limit; programmatically passing undefined is fine (falls back to defaultValue) but null-coalesced empty strings fail.

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