jackwener/OpenCLI · error · ArgumentError

--limit must be <= 25 (GitHub Trending lists at most 25 repo

Error message

--limit must be <= 25 (GitHub Trending lists at most 25 repositories)

What it means

GitHub's Trending page lists at most 25 repositories per view, so the CLI rejects `--limit` values above 25 with this ArgumentError rather than silently truncating or making multiple requests. It is a documented upper-bound on the option.

Source

Thrown at clis/github-trending/repos.js:125

    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',
                },
            });
        } catch (error) {
            throw new CommandExecutionError(`github-trending request failed: ${error?.message || error}`);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use --limit 25 (or omit the flag) — that is the maximum GitHub Trending exposes per page
  2. If more results are needed, combine language filters across separate invocations instead of raising the limit
  3. Adjust scripts to clamp the limit: Math.min(Number(x), 25)

Example fix

// before
opencli github-trending repos --limit 100
// after
opencli github-trending repos --limit 25
Defensive patterns

Strategy: validation

Validate before calling

function clampLimit(v) { return Math.min(Number(v ?? 25), 25); }
if (!Number.isInteger(limit) || limit <= 0 || limit > 25) throw new Error('--limit must be an integer 1-25');

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 (/limit must be <= 25/.test(e.message)) { console.error('Max is 25; clamping.'); limit = 25; }
  else throw e;
}

Prevention

When it happens

Trigger: Calling the command with `--limit 50`, `--limit 100`, or any integer > 25.

Common situations: Assuming the CLI paginates like the GitHub search API; copying a --limit convention (e.g. 100) from other tools; wanting 'all' trending repos and guessing a large number.

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


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