jackwener/OpenCLI · error · ArgumentError
amazon search query cannot be empty
Error message
amazon search query cannot be empty
What it means
An ArgumentError thrown by buildSearchUrl when the search query is empty or whitespace after cleaning. The library refuses to construct a search URL without a query because it would produce an invalid Amazon search endpoint. This is a fail-fast input validation error, not a scraping failure.
Source
Thrown at clis/amazon/shared.js:116
.map((line) => line.replace(/\s+/g, ' ').trim())
.filter(Boolean)
.join('\n')
: '';
}
export function uniqueNonEmpty(values) {
return [...new Set(values.map((value) => cleanText(value)).filter(Boolean))];
}
export function buildProvenance(sourceUrl) {
return {
source_url: sourceUrl,
fetched_at: new Date().toISOString(),
strategy: STRATEGY,
};
}
export function buildSearchUrl(query) {
const normalized = cleanText(query);
if (!normalized) {
throw new ArgumentError('amazon search query cannot be empty');
}
return `${SEARCH_URL_PREFIX}${encodeURIComponent(normalized)}`;
}
export function extractAsin(input) {
const normalized = cleanText(input);
if (!normalized)
return null;
if (/^[A-Z0-9]{10}$/i.test(normalized)) {
return normalized.toUpperCase();
}
const match = normalized.match(/\/(?:dp|gp\/product|product-reviews)\/([A-Z0-9]{10})/i);
return match ? match[1].toUpperCase() : null;
}
export function amazonHostFromInput(input) {
const normalized = cleanText(input);
if (!normalized)
return null;
try {View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a non-empty query string to the search command
- Check the shell variable/env var/config value feeding the query is set and non-blank
- Trim and validate the query in your script before invoking
Example fix
// before
const url = buildSearchUrl(query);
// after
if (!query?.trim()) throw new Error('query is required');
const url = buildSearchUrl(query); Defensive patterns
Strategy: validation
Validate before calling
const q = (process.env.SEARCH_QUERY ?? '').trim();
if (!q) throw new Error('SEARCH_QUERY is empty — set it before calling amazon search'); Type guard
const isNonEmptyString = (v) => typeof v === 'string' && v.trim().length > 0;
Try / catch
try {
const url = buildSearchUrl(query);
} catch (err) {
if (err.message.includes('query cannot be empty')) {
// fall back to a default query or surface a config error
} else throw err;
} Prevention
- Quote shell variables: "$Q" and check they are set
- Validate required inputs at script startup
- Trim inputs before passing
- Fail early on empty env/config values
When it happens
Trigger: Calling buildSearchUrl('') or buildSearchUrl(' ') directly, or passing an empty --query/positional argument to the amazon search command (e.g. from an unquoted shell variable that expands to nothing).
Common situations: Shell script with an unset variable: `opencli amazon search "$Q"` where Q is empty; reading the query from a config file or env var that is missing; trimming reduced the input to nothing.
Related errors
- oeis ${label} cannot be empty
- INVALID_ARGUMENT
- INVALID_ARGUMENT
- ${label} is required
- ${label} returned an unexpected payload shape; expected an o
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/2e843779d28d80a1.
Report an issue: GitHub.