jackwener/OpenCLI · error · ArgumentError
arxiv ${label} must be a positive integer
Error message
arxiv ${label} must be a positive integer What it means
ArgumentError thrown by normalizeArxivLimit when the supplied limit (after ?? default) is not a positive integer (Number.isInteger fails or value <= 0). The library requires result limits to be whole numbers >= 1 so it can safely build the arXiv max_results parameter.
Source
Thrown at clis/arxiv/utils.js:21
*
* arXiv exposes a public Atom/XML API — no key required.
* https://info.arxiv.org/help/api/index.html
*/
import { ArgumentError, CommandExecutionError } from '@jackwener/opencli/errors';
export const ARXIV_BASE = 'https://export.arxiv.org/api/query';
const ARXIV_CATEGORY_PATTERN = /^[a-z]+(?:-[a-z]+)*(?:\.[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*)?$/;
export async function arxivFetch(params) {
const resp = await fetch(`${ARXIV_BASE}?${params}`);
if (!resp.ok) {
throw new CommandExecutionError(`arXiv API HTTP ${resp.status}`, 'Check your search term or paper ID');
}
return resp.text();
}
export function normalizeArxivLimit(value, defaultValue, maxValue, label = 'limit') {
const raw = value ?? defaultValue;
const limit = Number(raw);
if (!Number.isInteger(limit) || limit <= 0) {
throw new ArgumentError(`arxiv ${label} must be a positive integer`);
}
if (limit > maxValue) {
throw new ArgumentError(`arxiv ${label} must be <= ${maxValue}`);
}
return limit;
}
export function normalizeArxivCategory(value) {
const category = String(value || '').trim();
if (!ARXIV_CATEGORY_PATTERN.test(category)) {
throw new ArgumentError(`Invalid arXiv category "${value}". Examples: cs.CL, cs.LG, math.PR, q-bio.NC, physics.comp-ph`);
}
return category;
}
/** Decode the small set of XML entities arXiv emits in text fields. */
function decodeEntities(s) {
return s
.replace(/&/g, '&')
.replace(/</g, '<')View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a positive integer (>= 1) for the limit option.
- Validate/parse the user input to an integer before calling the command.
- Omit the option to use the command's built-in default limit.
Example fix
// before opencli arxiv search 'transformers' --limit 0 // after opencli arxiv search 'transformers' --limit 10
Defensive patterns
Strategy: validation
Validate before calling
function assertPositiveInt(v) {
const n = Number(v);
if (!Number.isInteger(n) || n <= 0) throw new Error(`limit must be a positive integer, got ${v}`);
return n;
}
const limit = assertPositiveInt(opts.limit ?? 10); Type guard
function isPositiveInt(v) {
return typeof v === 'number' && Number.isInteger(v) && v > 0;
} Try / catch
try {
await run(['arxiv', 'search', term, '--limit', String(limit)]);
} catch (e) {
if (/must be a positive integer/.test(e.message)) {
console.error('Fix --limit: pass a whole number >= 1');
} else throw e;
} Prevention
- Always coerce and validate CLI/config numbers with Number.isInteger before use.
- Use schema validation (e.g. zod) on option objects.
- Prefer omitting the option over passing 0 to 'disable' limiting.
When it happens
Trigger: Passing limit = 0, a negative number, a non-numeric string like 'ten', a float like 2.5, NaN, or null when no default is provided to normalizeArxivLimit.
Common situations: CLI users typing --limit 0 or --limit abc; config files with string limits that Number() coerces to NaN; off-by-one code passing 0 to disable limiting.
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
- brand must be a non-empty value
- Search keyword cannot be empty
- dblp ${label} must be a positive integer
- dblp ${label} cannot be empty
- dblp paper key is required
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/bfeaa4f4263c9233.
Report an issue: GitHub.