jackwener/OpenCLI · error · ArgumentError
--limit must be a positive integer
Error message
--limit must be a positive integer
What it means
The `--limit` option of `opencli github-trending repos` must be a positive integer (default 25). Non-integer, zero, negative, or non-numeric values throw this ArgumentError. Validation runs after --since parsing and before any HTTP request.
Source
Thrown at clis/github-trending/repos.js:122
domain: 'github.com',
strategy: Strategy.PUBLIC,
browser: false,
args: [
{ name: 'since', type: 'string', default: 'daily', help: 'Time range: daily / weekly / monthly' },
{ name: 'language', type: 'string', default: '', help: 'Filter by programming language slug, e.g. python, rust, "c++"' },
{ name: 'limit', type: 'int', default: 25, help: 'Number of repositories to return (max 25)' },
],
columns: ['rank', 'repo', 'description', 'language', 'stars', 'forks', 'starsSince', 'url'],
func: async (args) => {
const sinceKey = String(args.since ?? 'daily').toLowerCase();
const since = SINCE[sinceKey];
if (!since) {
throw new ArgumentError(`Unknown --since "${sinceKey}". Valid: ${Object.keys(SINCE).join(', ')}`);
}
const n = Number(args.limit ?? 25);
if (!Number.isInteger(n) || n <= 0) {
throw new ArgumentError('--limit must be a positive integer');
}
if (n > 25) {
throw new ArgumentError('--limit must be <= 25 (GitHub Trending lists at most 25 repositories)');
}
const limit = n;
const language = String(args.language ?? '').trim();
const path = language ? `/trending/${encodeURIComponent(language)}` : '/trending';
const url = new URL(`https://github.com${path}`);
url.searchParams.set('since', since);
let resp;
try {
resp = await fetch(url, {
headers: {
'User-Agent': 'Mozilla/5.0 (compatible; opencli/github-trending)',
Accept: 'text/html',
},View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a positive integer between 1 and 25, e.g. --limit 10
- Omit --limit entirely to use the default of 25
- Fix the script logic producing a non-integer/empty value before invoking the CLI
Example fix
// before const lim = process.env.LIMIT; // "" -> NaN opencli github-trending repos --limit "$lim" // after const lim = process.env.LIMIT || "25"; opencli github-trending repos --limit "$lim"
Defensive patterns
Strategy: validation
Validate before calling
function validateLimit(v) {
const n = Number(v ?? 25);
if (!Number.isInteger(n) || n <= 0) throw new Error('--limit must be a positive integer');
return n;
} Type guard
function isArgumentError(e) { return e instanceof Error && e.name === 'ArgumentError'; } Try / catch
try {
await run(['opencli', 'github-trending', 'repos', '--limit', String(limit)]);
} catch (e) {
if (e.name === 'ArgumentError') { console.error(e.message); process.exitCode = 2; }
else throw e;
} Prevention
- Coerce and validate limit as a positive integer in scripts before invoking
- Treat empty env/variables as the default (25) rather than passing them raw
- Remember 0 is invalid — there is no 'unlimited' via --limit
When it happens
Trigger: Passing `--limit 0`, `--limit -5`, `--limit abc`, `--limit 2.5`, or a value that `Number()` coerces to NaN/non-integer.
Common situations: Computing the limit from a shell variable that ends up empty (`--limit ""` -> NaN); using a float from a config; sign/typo errors like `--limit -1`; expecting 0 to mean 'unlimited' (it does not).
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
- tid must be a numeric thread id
- --from and --to must differ (got ${fromCity})
- --from and --to must differ (got ${fromCode})
- --from and --to must differ (got ${fromName})
- Unknown --since "${sinceKey}". Valid: ${Object.keys(SINCE).j
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/ce92af534eaae65f.
Report an issue: GitHub.