jackwener/OpenCLI · error · ArgumentError

archive search limit must be <= 100

Error message

archive search limit must be <= 100

What it means

This ArgumentError is thrown before any network call by `archive search` when `limit` is a valid positive integer but exceeds the hard cap of 100. The command fetches a single API page, so anything above 100 cannot be served in one request. It is a client-side input validation error.

Source

Thrown at clis/archive/search.js:43

        { name: 'sort', type: 'string', default: 'downloads', help: `Sort key: ${SORT_OPTIONS.join(', ')}` },
        { name: 'limit', type: 'int', default: 20, help: 'Max items (max 100; one API page).' },
    ],
    columns: ['rank', 'identifier', 'title', 'creator', 'date', 'mediatype', 'downloads', 'url'],
    func: async (args) => {
        const sortRaw = String(args.sort ?? 'downloads').toLowerCase();
        const sort = SORT_ALIAS[sortRaw] ?? sortRaw;
        if (!SORT_OPTIONS.includes(sort)) {
            throw new ArgumentError(`archive search sort must be one of ${SORT_OPTIONS.join(', ')}`);
        }
        if (args.mediatype && !MEDIATYPES.includes(String(args.mediatype))) {
            throw new ArgumentError(`archive search mediatype must be one of ${MEDIATYPES.join(', ')}`);
        }
        const limit = Number(args.limit ?? 20);
        if (!Number.isInteger(limit) || limit <= 0) {
            throw new ArgumentError('archive search limit must be a positive integer');
        }
        if (limit > 100) {
            throw new ArgumentError('archive search limit must be <= 100');
        }

        const query = String(args.query ?? '').trim();
        if (!query) {
            throw new ArgumentError('archive search query must not be empty');
        }

        const fullQuery = args.mediatype
            ? `(${query}) AND mediatype:${args.mediatype}`
            : query;

        const url = new URL('https://archive.org/advancedsearch.php');
        url.searchParams.set('q', fullQuery);
        url.searchParams.set('output', 'json');
        url.searchParams.set('rows', String(limit));
        url.searchParams.set('sort[]', `${sort} desc`);
        for (const fl of ['identifier', 'title', 'creator', 'date', 'mediatype', 'downloads']) {
            url.searchParams.append('fl[]', fl);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Lower --limit to 100 or less; use more specific query terms instead of a bigger page
  2. Run multiple searches with narrower queries to cover more results
  3. If you need >100 results, fetch directly from archive.org's advancedsearch endpoint with pagination (page/rows) outside this CLI

Example fix

// before
opencli archive search "public domain music" --limit 500
// after
opencli archive search "public domain music" --limit 100
Defensive patterns

Strategy: validation

Validate before calling

const limit = Math.min(Number(rawLimit ?? 20), 100);
if (!Number.isInteger(limit) || limit <= 0) {
    throw new Error('limit must be a positive integer <= 100');
}

Type guard

const isValidLimit = (n) => Number.isInteger(n) && n > 0 && n <= 100;

Try / catch

try {
    rows = await run(['archive', 'search', query, '--limit', String(limit)]);
} catch (err) {
    if (err instanceof ArgumentError && err.message.includes('limit must be <= 100')) {
        rows = await run(['archive', 'search', query, '--limit', '100']);
    } else { throw err; }
}

Prevention

When it happens

Trigger: Calling `opencli archive search <query> --limit 200` (or any value > 100). Values like 100 and below pass; 101+ throw.

Common situations: Assuming the CLI paginates automatically and requesting 500 results; copying page sizes from APIs with larger caps; wanting 'everything' for a small query and passing a huge 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/7dc55f1c385226f4. Report an issue: GitHub.