{"record":{"id":"db52ac0a0f036584","repo":"jackwener/OpenCLI","slug":"arxiv-search-query-cannot-be-empty","errorCode":null,"errorMessage":"arxiv search query cannot be empty","messagePattern":"arxiv search query cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/arxiv/search.js","lineNumber":19,"sourceCode":"import { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, EmptyResultError } from '@jackwener/opencli/errors';\nimport { arxivFetch, normalizeArxivLimit, parseEntries } from './utils.js';\ncli({\n    site: 'arxiv',\n    name: 'search',\n    access: 'read',\n    description: 'Search arXiv papers',\n    strategy: Strategy.PUBLIC,\n    browser: false,\n    args: [\n        { name: 'query', positional: true, required: true, help: 'Search keyword (e.g. \"attention is all you need\")' },\n        { name: 'limit', type: 'int', default: 10, help: 'Max results (max 25)' },\n    ],\n    columns: ['id', 'title', 'authors', 'published', 'primary_category', 'url'],\n    func: async (args) => {\n        const queryText = String(args.query || '').trim();\n        if (!queryText) {\n            throw new ArgumentError('arxiv search query cannot be empty');\n        }\n        const limit = normalizeArxivLimit(args.limit, 10, 25);\n        const query = encodeURIComponent(`all:${queryText}`);\n        const xml = await arxivFetch(`search_query=${query}&max_results=${limit}&sortBy=relevance`);\n        const entries = parseEntries(xml);\n        if (!entries.length)\n            throw new EmptyResultError('arxiv', 'No papers found. Try a different keyword.');\n        return entries.map(e => ({\n            id: e.id,\n            title: e.title,\n            authors: e.authors,\n            published: e.published,\n            primary_category: e.primary_category,\n            url: e.url,\n        }));\n    },\n});\n","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/arxiv/search.js#L1-L37","documentation":"An ArgumentError thrown before any network call when the `query` argument to `arxiv search` is missing, empty, or whitespace-only. Like the author validation, it fails fast with a clear message rather than issuing a degenerate arXiv query. Nothing is sent to the arXiv API when this fires.","triggerScenarios":"Running `opencli arxiv search` with no argument, `--query \"\"`, or whitespace-only input; shell quoting that drops the argument; a script variable that is empty due to an upstream failure.","commonSituations":"Missing quotes around multi-word queries so the shell eats them; empty search boxes in wrappers passing through unvalidated; CI scripts where the query comes from an empty config/env value.","solutions":["Provide a non-empty query: opencli arxiv search \"attention is all you need\"","Quote multi-word queries so the shell passes them as one argument","If scripted, validate the query variable is non-empty and trimmed before invoking","Check env/config sources for empty values feeding the query"],"exampleFix":"// before\nrun(`opencli arxiv search ${q}`); // q may be empty/unquoted\n// after\nconst query = (q || '').trim();\nif (!query) throw new Error('search query is required');\nrun(`opencli arxiv search \"${query}\"`);","handlingStrategy":"validation","validationCode":"const query = String(userQuery || '').trim();\nif (!query) throw new Error('search query required');","typeGuard":"function hasQuery(q) { return typeof q === 'string' && q.trim().length > 0; }","tryCatchPattern":"try {\n  await exec('opencli arxiv search ' + JSON.stringify(query));\n} catch (e) {\n  if (e.message.includes('query cannot be empty')) {\n    console.error('Provide a non-empty quoted query, e.g. opencli arxiv search \"transformers\"');\n    process.exitCode = 1;\n    return;\n  }\n  throw e;\n}","preventionTips":["Quote multi-word queries in the shell","Trim/validate query variables sourced from config or env before invoking","Prompt interactively instead of passing empty strings","Fail fast in wrapper scripts when the query is blank"],"tags":["validation","input","arxiv","cli"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}