{"record":{"id":"7dc55f1c385226f4","repo":"jackwener/OpenCLI","slug":"archive-search-limit-must-be-100","errorCode":null,"errorMessage":"archive search limit must be <= 100","messagePattern":"archive search limit must be <= 100","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/archive/search.js","lineNumber":43,"sourceCode":"        { name: 'sort', type: 'string', default: 'downloads', help: `Sort key: ${SORT_OPTIONS.join(', ')}` },\n        { name: 'limit', type: 'int', default: 20, help: 'Max items (max 100; one API page).' },\n    ],\n    columns: ['rank', 'identifier', 'title', 'creator', 'date', 'mediatype', 'downloads', 'url'],\n    func: async (args) => {\n        const sortRaw = String(args.sort ?? 'downloads').toLowerCase();\n        const sort = SORT_ALIAS[sortRaw] ?? sortRaw;\n        if (!SORT_OPTIONS.includes(sort)) {\n            throw new ArgumentError(`archive search sort must be one of ${SORT_OPTIONS.join(', ')}`);\n        }\n        if (args.mediatype && !MEDIATYPES.includes(String(args.mediatype))) {\n            throw new ArgumentError(`archive search mediatype must be one of ${MEDIATYPES.join(', ')}`);\n        }\n        const limit = Number(args.limit ?? 20);\n        if (!Number.isInteger(limit) || limit <= 0) {\n            throw new ArgumentError('archive search limit must be a positive integer');\n        }\n        if (limit > 100) {\n            throw new ArgumentError('archive search limit must be <= 100');\n        }\n\n        const query = String(args.query ?? '').trim();\n        if (!query) {\n            throw new ArgumentError('archive search query must not be empty');\n        }\n\n        const fullQuery = args.mediatype\n            ? `(${query}) AND mediatype:${args.mediatype}`\n            : query;\n\n        const url = new URL('https://archive.org/advancedsearch.php');\n        url.searchParams.set('q', fullQuery);\n        url.searchParams.set('output', 'json');\n        url.searchParams.set('rows', String(limit));\n        url.searchParams.set('sort[]', `${sort} desc`);\n        for (const fl of ['identifier', 'title', 'creator', 'date', 'mediatype', 'downloads']) {\n            url.searchParams.append('fl[]', fl);","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/archive/search.js#L25-L61","documentation":"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.","triggerScenarios":"Calling `opencli archive search <query> --limit 200` (or any value > 100). Values like 100 and below pass; 101+ throw.","commonSituations":"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.","solutions":["Lower --limit to 100 or less; use more specific query terms instead of a bigger page","Run multiple searches with narrower queries to cover more results","If you need >100 results, fetch directly from archive.org's advancedsearch endpoint with pagination (page/rows) outside this CLI"],"exampleFix":"// before\nopencli archive search \"public domain music\" --limit 500\n// after\nopencli archive search \"public domain music\" --limit 100","handlingStrategy":"validation","validationCode":"const limit = Math.min(Number(rawLimit ?? 20), 100);\nif (!Number.isInteger(limit) || limit <= 0) {\n    throw new Error('limit must be a positive integer <= 100');\n}","typeGuard":"const isValidLimit = (n) => Number.isInteger(n) && n > 0 && n <= 100;","tryCatchPattern":"try {\n    rows = await run(['archive', 'search', query, '--limit', String(limit)]);\n} catch (err) {\n    if (err instanceof ArgumentError && err.message.includes('limit must be <= 100')) {\n        rows = await run(['archive', 'search', query, '--limit', '100']);\n    } else { throw err; }\n}","preventionTips":["Clamp limit to 100 at the call site with Math.min","Remember the CLI serves one page only; paginate outside it if you need more","Validate config-sourced page sizes against the cap at startup","Prefer narrowing the query over inflating the limit"],"tags":["validation","cli","argument-error","limit"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}