jackwener/OpenCLI · error · ArgumentError
${label} cannot be empty
Error message
${label} cannot be empty What it means
requireSearchQuery in the shared search adapter trims its input and throws ArgumentError '<label> cannot be empty' (default label 'keyword') when the result is empty. It is the search-specific equivalent of requireNonEmptyQuery used by keyword-driven search commands.
Source
Thrown at clis/_shared/search-adapter.js:6
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
export function requireSearchQuery(value, label = 'keyword') {
const query = String(value ?? '').trim();
if (!query) {
throw new ArgumentError(`${label} cannot be empty`);
}
return query;
}
export function requireBoundedInteger(value, defaultValue, min, max, label) {
const raw = value ?? defaultValue;
const parsed = typeof raw === 'number' ? raw : Number(raw);
if (!Number.isInteger(parsed)) {
throw new ArgumentError(`${label} must be an integer between ${min} and ${max}, got ${JSON.stringify(value)}`);
}
if (parsed < min || parsed > max) {
throw new ArgumentError(`${label} must be between ${min} and ${max}, got ${parsed}`);
}
return parsed;
}
export function requireNonNegativeInteger(value, defaultValue, label) {
const raw = value ?? defaultValue;View on GitHub (pinned to 49907e53dc)
Solutions
- Supply a non-empty keyword (trimmed) to the search command.
- Fail fast in scripts when the keyword variable is empty before invoking the CLI.
- Pass an explicit label when wrapping so error messages name the actual option (e.g. 'query' vs 'keyword').
Example fix
// before
requireSearchQuery(process.env.KEYWORD) // KEYWORD unset -> ''
// after
const kw = (process.env.KEYWORD ?? '').trim();
if (!kw) throw new Error('KEYWORD env var is required');
requireSearchQuery(kw); Defensive patterns
Strategy: validation
Validate before calling
const kw = String(value ?? '').trim();
if (!kw) throw new Error('keyword is required'); Type guard
const hasKeyword = (v) => typeof v === 'string' && v.trim().length > 0;
Try / catch
try {
const keyword = requireSearchQuery(raw);
} catch (err) {
if (err.name === 'ArgumentError' && err.message.includes('cannot be empty')) {
console.error('Search keyword missing; supply a non-empty --keyword.');
}
throw err;
} Prevention
- Default empty keywords to an explicit error instead of empty string in scripts.
- Validate env vars/config fields before passing to search commands.
- Pass a descriptive label so errors name the actual option.
When it happens
Trigger: Calling requireSearchQuery with '', whitespace, null or undefined — e.g. a keyword CLI option omitted or bound to an empty shell variable.
Common situations: Unset keyword variable in automation scripts; user pressing enter at an interactive prompt; empty field in a YAML/JSON config driving the search; tokenization stripping all characters from the input.
Related errors
- ${label} cannot be empty
- twitter search query is empty
- No 12306 stations match "${keyword}"
- ${label} is required
- ${label} must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/05f3d8d63f899bee.
Report an issue: GitHub.