{"record":{"id":"9aea2cefeceed81e","repo":"jackwener/OpenCLI","slug":"archive-search-query-must-not-be-empty","errorCode":null,"errorMessage":"archive search query must not be empty","messagePattern":"archive search query must not be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/archive/search.js","lineNumber":48,"sourceCode":"        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);\n        }\n\n        let resp;\n        try {\n            resp = await fetch(url, {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/archive/search.js#L30-L66","documentation":"This ArgumentError is thrown before any network call by `archive search` when the positional `query` argument is empty after trimming. A blank search would hit archive.org with an empty `q` parameter, so the CLI rejects it up front. It is a client-side input validation error.","triggerScenarios":"Calling `opencli archive search \"\"`, `opencli archive search \"   \"`, or omitting the positional query entirely so args.query is undefined (coerced to '').","commonSituations":"Shell variable holding the search term is unset or whitespace-only; quoting mistakes pass an empty string; script pipes lose the term before it reaches the command.","solutions":["Provide a non-empty search term as the positional argument","In scripts, guard: [ -n \"${TERM// /}\" ] before invoking, or default the term","If you want to browse rather than search, use a broad term like the OR operator in archive.org query syntax, e.g. 'mediatype:texts' as the query"],"exampleFix":"// before\nopencli archive search \"$QUERY\"   # QUERY empty\n// after\n: \"${QUERY:?QUERY must be a non-empty search term}\"\nopencli archive search \"$QUERY\"","handlingStrategy":"validation","validationCode":"const query = String(rawQuery ?? '').trim();\nif (!query) {\n    throw new Error('search query must not be empty');\n}","typeGuard":"const hasQuery = (q) => typeof q === 'string' && q.trim().length > 0;","tryCatchPattern":"try {\n    rows = await run(['archive', 'search', query]);\n} catch (err) {\n    if (err instanceof ArgumentError && err.message.includes('query must not be empty')) {\n        console.error('No search term provided; nothing to do.');\n        process.exitCode = 2;\n    } else { throw err; }\n}","preventionTips":["Trim and check non-empty before invoking in scripts","Use ${VAR:?} shell guards for variables feeding the positional query","Validate CLI parameters at the entry point of wrappers","Quote positional arguments so whitespace-only strings are passed predictably"],"tags":["validation","cli","argument-error","input"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}