jackwener/OpenCLI · error · ArgumentError
archive search mediatype must be one of ${MEDIATYPES.join(',
Error message
archive search mediatype must be one of ${MEDIATYPES.join(', ')} What it means
This ArgumentError is thrown before any network call by `archive search` when a `mediatype` argument is supplied but is not one of MEDIATYPES ('texts', 'movies', 'audio', 'software', 'image', 'web', 'data', 'collection'). Unlike sort, no aliasing or lowercasing is applied to mediatype, so case must match exactly. It is purely client-side validation of the filter argument.
Source
Thrown at clis/archive/search.js:36
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.mediatype
? `(${query}) AND mediatype:${args.mediatype}`
: query;
View on GitHub (pinned to 49907e53dc)
Solutions
- Use an exact whitelisted value: texts, movies, audio, software, image, web, data, collection
- Fix casing — mediatype is matched case-sensitively, so use lowercase plural forms
- Omit --mediatype to search across all mediatypes
Example fix
// before opencli archive search "sherlock holmes" --mediatype Books // after opencli archive search "sherlock holmes" --mediatype texts
Defensive patterns
Strategy: validation
Validate before calling
const MEDIATYPES = ['texts','movies','audio','software','image','web','data','collection'];
if (mediatype && !MEDIATYPES.includes(String(mediatype))) {
throw new Error(`mediatype must be one of ${MEDIATYPES.join(', ')}`);
} Type guard
const isMediatype = (m) => ['texts','movies','audio','software','image','web','data','collection'].includes(m);
Try / catch
try {
rows = await run(['archive', 'search', query, '--mediatype', mediatype]);
} catch (err) {
if (err instanceof ArgumentError && err.message.includes('mediatype must be one of')) {
rows = await run(['archive', 'search', query]); // search without mediatype filter
} else { throw err; }
} Prevention
- Use the exact lowercase plural enum values from the CLI help
- Remember the check is case-sensitive — never pass 'Texts' or 'Book'
- Drop the --mediatype flag to search all mediatypes
- Centralize the mediatype enum in your own code instead of hardcoding strings ad hoc
When it happens
Trigger: Calling `opencli archive search <query> --mediatype <value>` where <value> is not an exact member of the whitelist — e.g. --mediatype Books, --mediatype text (singular), --mediatype video (not in list), or --mediatype ebooks.
Common situations: Guessing mediatype names ('book', 'movie' singular, 'video'); copying taxonomy labels from the archive.org UI instead of its API enum values; forgetting that the check is case-sensitive so 'Texts' fails.
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 sort must be one of ${SORT_OPTIONS.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/13355f20a051baf7.
Report an issue: GitHub.