jackwener/OpenCLI · error · ArgumentError
arxiv search query cannot be empty
Error message
arxiv search query cannot be empty
What it means
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.
Source
Thrown at clis/arxiv/search.js:19
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, EmptyResultError } from '@jackwener/opencli/errors';
import { arxivFetch, normalizeArxivLimit, parseEntries } from './utils.js';
cli({
site: 'arxiv',
name: 'search',
access: 'read',
description: 'Search arXiv papers',
strategy: Strategy.PUBLIC,
browser: false,
args: [
{ name: 'query', positional: true, required: true, help: 'Search keyword (e.g. "attention is all you need")' },
{ name: 'limit', type: 'int', default: 10, help: 'Max results (max 25)' },
],
columns: ['id', 'title', 'authors', 'published', 'primary_category', 'url'],
func: async (args) => {
const queryText = String(args.query || '').trim();
if (!queryText) {
throw new ArgumentError('arxiv search query cannot be empty');
}
const limit = normalizeArxivLimit(args.limit, 10, 25);
const query = encodeURIComponent(`all:${queryText}`);
const xml = await arxivFetch(`search_query=${query}&max_results=${limit}&sortBy=relevance`);
const entries = parseEntries(xml);
if (!entries.length)
throw new EmptyResultError('arxiv', 'No papers found. Try a different keyword.');
return entries.map(e => ({
id: e.id,
title: e.title,
authors: e.authors,
published: e.published,
primary_category: e.primary_category,
url: e.url,
}));
},
});
View on GitHub (pinned to 49907e53dc)
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
Example fix
// before
run(`opencli arxiv search ${q}`); // q may be empty/unquoted
// after
const query = (q || '').trim();
if (!query) throw new Error('search query is required');
run(`opencli arxiv search "${query}"`); Defensive patterns
Strategy: validation
Validate before calling
const query = String(userQuery || '').trim();
if (!query) throw new Error('search query required'); Type guard
function hasQuery(q) { return typeof q === 'string' && q.trim().length > 0; } Try / catch
try {
await exec('opencli arxiv search ' + JSON.stringify(query));
} catch (e) {
if (e.message.includes('query cannot be empty')) {
console.error('Provide a non-empty quoted query, e.g. opencli arxiv search "transformers"');
process.exitCode = 1;
return;
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- arxiv author cannot be empty
- archive search sort must be one of ${SORT_OPTIONS.join(', ')
- archive search mediatype must be one of ${MEDIATYPES.join(',
- archive search limit must be a positive integer
- archive search query must not be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/db52ac0a0f036584.
Report an issue: GitHub.