{"record":{"id":"92cfd3c507f5da74","repo":"jackwener/OpenCLI","slug":"search-query-cannot-be-empty","errorCode":null,"errorMessage":"Search query cannot be empty","messagePattern":"Search query cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/imdb/search.js","lineNumber":24,"sourceCode":" */\ncli({\n    site: 'imdb',\n    name: 'search',\n    access: 'read',\n    description: 'Search IMDb for movies, TV shows, and people',\n    domain: 'www.imdb.com',\n    strategy: Strategy.PUBLIC,\n    browser: true,\n    args: [\n        { name: 'query', positional: true, required: true, help: 'Search query' },\n        { name: 'limit', type: 'int', default: 20, help: 'Number of results' },\n    ],\n    columns: ['rank', 'id', 'title', 'year', 'type', 'url'],\n    func: async (page, args) => {\n        const query = String(args.query || '').trim();\n        // Reject empty or whitespace-only queries early\n        if (!query) {\n            throw new ArgumentError('Search query cannot be empty');\n        }\n        const limit = Math.max(1, Math.min(Number(args.limit) || 20, 50));\n        const url = forceEnglishUrl(`https://www.imdb.com/find/?q=${encodeURIComponent(query)}&ref_=nv_sr_sm`);\n        await page.goto(url);\n        const onSearchPage = await waitForImdbPath(page, '^/find/?$');\n        const searchReady = await waitForImdbSearchReady(page, 15000);\n        if (await isChallengePage(page)) {\n            throw new CommandExecutionError('IMDb blocked this request', 'Try again with a normal browser session or extension mode');\n        }\n        if (!onSearchPage || !searchReady) {\n            throw new CommandExecutionError('IMDb search results did not finish loading', 'Retry the command; if it persists, the search page structure may have changed');\n        }\n        const results = await page.evaluate(`\n      (function() {\n        var results = [];\n\n        function pushResult(item) {\n          if (!item || !item.id || !item.title) {","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/imdb/search.js#L6-L42","documentation":"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.","triggerScenarios":"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 = '   ').","commonSituations":"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.","solutions":["Provide a non-empty query argument to the search command.","Trim and check the query in the calling code before invoking the command.","If the query comes from config or environment, verify the value is actually populated at runtime."],"exampleFix":"// before\nawait imdbSearch({ query: process.env.Q, limit: 10 });\n// after\nconst q = (process.env.Q || '').trim();\nif (!q) throw new Error('Q env var must contain a search query');\nawait imdbSearch({ query: q, limit: 10 });","handlingStrategy":"validation","validationCode":"const q = String(args.query ?? '').trim();\nif (!q) throw new Error('query must be a non-empty string');\nawait imdbSearch({ query: q, limit: 10 });","typeGuard":"function hasQuery(args) {\n  return typeof args.query === 'string' && args.query.trim().length > 0;\n}","tryCatchPattern":"try {\n  await imdbSearch({ query });\n} catch (e) {\n  if (e.name === 'ArgumentError' || /cannot be empty/.test(e.message)) {\n    console.error('Provide a search query');\n  } else throw e;\n}","preventionTips":["Always trim and truthiness-check user-supplied queries before calling search.","Validate CLI/env inputs at the entry point of your script.","Fail fast with your own descriptive error when required args are missing."],"tags":["validation","argument-error","input-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}