jackwener/OpenCLI · error · ArgumentError
Search query cannot be empty
Error message
Search query cannot be empty
What it means
An ArgumentError thrown by the Reuters search command when kwargs.query is missing, empty, or only whitespace after trimming. The library validates the search keyword up front because Reuters site search cannot proceed without a query term.
Source
Thrown at clis/reuters/search.js:27
import { buildSearchScript, isAuthStatus, looksAuthWallText, mapSearchArticles, parseLimit } from './utils.js';
cli({
site: 'reuters',
name: 'search',
access: 'read',
description: 'Reuters 路透社新闻搜索',
domain: 'www.reuters.com',
strategy: Strategy.COOKIE,
args: [
{ name: 'query', required: true, positional: true, help: 'Search query' },
{ name: 'limit', type: 'int', default: 10, help: 'Number of results (1-40)' },
],
columns: ['rank', 'title', 'date', 'section', 'section_path', 'authors', 'url'],
func: async (page, kwargs) => {
const limit = parseLimit(kwargs.limit);
const query = String(kwargs.query || '').trim();
if (!query) {
throw new ArgumentError('Search query cannot be empty', 'Provide a non-empty keyword');
}
await page.goto('https://www.reuters.com');
await page.wait(2);
const result = await page.evaluate(buildSearchScript(query, limit));
if (result?.error) {
throw new CommandExecutionError(`Reuters search failed inside the page: ${result.error}`);
}
if (!result || typeof result !== 'object') {
throw new CommandExecutionError('Reuters search API returned an unreadable response');
}
if (isAuthStatus(result.status) || looksAuthWallText(result.textPreview)) {
throw new AuthRequiredError(
'www.reuters.com',
`Reuters search requires an accessible Reuters browser session or completed human verification${result.status ? ` (HTTP ${result.status})` : ''}`,
);
}
if (result.ok !== true) {
const status = Number.isFinite(result.status) && result.status > 0View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a non-empty query kwarg, e.g. { query: 'inflation' }.
- Trim and validate the query in the caller before invoking the command.
- If the query comes from user input or CLI args, add a required-argument check that fails early with a clear message.
Example fix
// before
await reutersSearch({ query: userInput });
// after
const q = String(userInput || '').trim();
if (!q) throw new Error('query is required');
await reutersSearch({ query: q }); Defensive patterns
Strategy: validation
Validate before calling
function requireQuery(kwargs) {
const q = String(kwargs && kwargs.query || '').trim();
if (!q) throw new Error('query is required and must be non-empty');
return q;
}
const query = requireQuery(userKwargs); // call before invoking the search command Type guard
function hasNonEmptyQuery(kwargs) {
return kwargs != null && typeof kwargs.query === 'string' && kwargs.query.trim().length > 0;
} Try / catch
try {
await runCommand('reuters', 'search', { query });
} catch (e) {
if (e instanceof ArgumentError && /Search query cannot be empty/.test(e.message)) {
console.error('Please supply a non-empty --query value');
process.exitCode = 2;
} else {
throw e;
}
} Prevention
- Validate CLI/kwargs input for required fields before dispatching commands.
- Trim user-supplied queries and reject whitespace-only values early.
- Never pass raw, possibly-undefined objects straight into command kwargs.
- Surface the ArgumentError's remedy hint ('Provide a non-empty keyword') in CLI help text.
When it happens
Trigger: Calling the reuters search command with query absent (undefined), an empty string, or a string of only whitespace — String(kwargs.query || '').trim() yields '' at clis/reuters/search.js:27.
Common situations: Caller forgot to pass the query kwarg, passed query: null, read the query from an empty CLI flag or env var, or built the kwargs dynamically from user input that was blank.
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
- symbol is required
- <username> is required
- <game-url> is required
- Either --product-id or --url is required
- --city is required (numeric city ID from `ctrip search` or `
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/ff507e49d1490a89.
Report an issue: GitHub.