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
- Pass a positive whole number, e.g. `medium tag programming --limit 10`.
- Omit --limit entirely to use the default value handled by requireBoundedInt.
- If building the value in a script, coerce with Math.floor(Number(value)) and validate Number.isInteger(n) && n > 0 before calling.
- 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
- Always pass limits as stringified integers when shelling out.
- Avoid sentinel words like 'all'/'max' — use the default by omitting the flag.
- Coerce and validate with Number.isInteger before invoking the CLI.
- Document limit semantics in scripts that wrap the command.
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
- archive search sort must be one of ${SORT_OPTIONS.join(', ')
- archive search mediatype must be one of ${MEDIATYPES.join(',
- archive search limit must be a positive integer
- archive search limit must be <= 100
- archive search query must not be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/f4874305943c283c.
Report an issue: GitHub.