jackwener/OpenCLI · error · ArgumentError
archive search sort must be one of ${SORT_OPTIONS.join(', ')
Error message
archive search sort must be one of ${SORT_OPTIONS.join(', ')} What it means
This ArgumentError is thrown before any network call by `archive search` when the resolved `sort` value is not one of SORT_OPTIONS ('downloads', 'date', 'addeddate', 'week', 'title'). Input is lowercased and passed through SORT_ALIAS ('added'->'addeddate', 'published'->'date') first, so only values outside that whitelist fail. It is a client-side input validation error.
Source
Thrown at clis/archive/search.js:33
site: 'archive',
name: 'search',
access: 'read',
description: 'Search Internet Archive items across books, movies, audio, software, and web.',
domain: 'archive.org',
strategy: Strategy.PUBLIC,
browser: false,
args: [
{ name: 'query', positional: true, required: true, help: 'Full-text query (matches title, description, creator, subject).' },
{ name: 'mediatype', type: 'string', required: false, help: `Restrict to mediatype: ${MEDIATYPES.join(', ')}` },
{ 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.mediatypeView on GitHub (pinned to 49907e53dc)
Solutions
- Use one of the allowed values: downloads, date, addeddate, week, title
- Use the built-in aliases: 'added' (for addeddate) or 'published' (for date)
- Omit --sort entirely to get the default 'downloads' ordering
Example fix
// before opencli archive search "folk songs" --sort relevance // after opencli archive search "folk songs" --sort downloads
Defensive patterns
Strategy: validation
Validate before calling
const SORT_OPTIONS = ['downloads', 'date', 'addeddate', 'week', 'title'];
const SORT_ALIAS = { added: 'addeddate', published: 'date' };
const sort = SORT_ALIAS[String(rawSort).toLowerCase()] ?? String(rawSort).toLowerCase();
if (!SORT_OPTIONS.includes(sort)) throw new Error(`sort must be one of ${SORT_OPTIONS.join(', ')}`); Type guard
const isSortOption = (s) => ['downloads','date','addeddate','week','title'].includes(s);
Try / catch
try {
rows = await run(['archive', 'search', query, '--sort', sort]);
} catch (err) {
if (err instanceof ArgumentError && err.message.includes('sort must be one of')) {
rows = await run(['archive', 'search', query]); // fall back to default sort
} else { throw err; }
} Prevention
- Whitelist sort values at the call site before invoking the CLI
- Normalize user input with toLowerCase and the known aliases first
- Omit --sort when unsure; the default 'downloads' is always valid
- Keep the option list synced with the CLI's --help output
When it happens
Trigger: Calling `opencli archive search <query> --sort <value>` where <value> (after lowercasing and alias mapping) is not exactly one of downloads, date, addeddate, week, title — e.g. --sort relevance, --sort pubdate, or a typo like --sort downlods.
Common situations: Copying sort keys from other search APIs (relevance, newest); using field names like 'year' or 'publisher' that archive.org supports in query syntax but are not whitelisted here; capitalization is fine (lowercased) but hyphenated variants like 'added-date' fail.
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
- archive search mediatype must be one of ${MEDIATYPES.join(',
- archive search limit must be a positive integer
- archive search query must not be empty
- archive search limit must be <= 100
- arxiv author cannot be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/7dfe0570af8a8f3b.
Report an issue: GitHub.