jackwener/OpenCLI · error · ArgumentError

Search query cannot be empty

Error message

Search query cannot be empty

What it means

The imdb search command throws ArgumentError when the query argument is empty or whitespace-only. The code trims String(args.query || '') and rejects it early before any navigation, because an empty query would produce a useless IMDb /find/ URL. It fails fast at clis/imdb/search.js:24 instead of letting the browser load a blank search page.

Source

Thrown at clis/imdb/search.js:24

 */
cli({
    site: 'imdb',
    name: 'search',
    access: 'read',
    description: 'Search IMDb for movies, TV shows, and people',
    domain: 'www.imdb.com',
    strategy: Strategy.PUBLIC,
    browser: true,
    args: [
        { name: 'query', positional: true, required: true, help: 'Search query' },
        { name: 'limit', type: 'int', default: 20, help: 'Number of results' },
    ],
    columns: ['rank', 'id', 'title', 'year', 'type', 'url'],
    func: async (page, args) => {
        const query = String(args.query || '').trim();
        // Reject empty or whitespace-only queries early
        if (!query) {
            throw new ArgumentError('Search query cannot be empty');
        }
        const limit = Math.max(1, Math.min(Number(args.limit) || 20, 50));
        const url = forceEnglishUrl(`https://www.imdb.com/find/?q=${encodeURIComponent(query)}&ref_=nv_sr_sm`);
        await page.goto(url);
        const onSearchPage = await waitForImdbPath(page, '^/find/?$');
        const searchReady = await waitForImdbSearchReady(page, 15000);
        if (await isChallengePage(page)) {
            throw new CommandExecutionError('IMDb blocked this request', 'Try again with a normal browser session or extension mode');
        }
        if (!onSearchPage || !searchReady) {
            throw new CommandExecutionError('IMDb search results did not finish loading', 'Retry the command; if it persists, the search page structure may have changed');
        }
        const results = await page.evaluate(`
      (function() {
        var results = [];

        function pushResult(item) {
          if (!item || !item.id || !item.title) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Provide a non-empty query argument to the search command.
  2. Trim and check the query in the calling code before invoking the command.
  3. If the query comes from config or environment, verify the value is actually populated at runtime.

Example fix

// before
await imdbSearch({ query: process.env.Q, limit: 10 });
// after
const q = (process.env.Q || '').trim();
if (!q) throw new Error('Q env var must contain a search query');
await imdbSearch({ query: q, limit: 10 });
Defensive patterns

Strategy: validation

Validate before calling

const q = String(args.query ?? '').trim();
if (!q) throw new Error('query must be a non-empty string');
await imdbSearch({ query: q, limit: 10 });

Type guard

function hasQuery(args) {
  return typeof args.query === 'string' && args.query.trim().length > 0;
}

Try / catch

try {
  await imdbSearch({ query });
} catch (e) {
  if (e.name === 'ArgumentError' || /cannot be empty/.test(e.message)) {
    console.error('Provide a search query');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the imdb search command with args.query undefined, null, an empty string, or a string containing only spaces (e.g. args.query = '' or args.query = ' ').

Common situations: Passing an unbound CLI flag, a shell variable that expands to nothing, reading query from an empty config/env value, or piping input where the query field was never set.

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


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/92cfd3c507f5da74. Report an issue: GitHub.