{"record":{"id":"ff507e49d1490a89","repo":"jackwener/OpenCLI","slug":"search-query-cannot-be-empty-ff507e","errorCode":null,"errorMessage":"Search query cannot be empty","messagePattern":"Search query cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/reuters/search.js","lineNumber":27,"sourceCode":"import { buildSearchScript, isAuthStatus, looksAuthWallText, mapSearchArticles, parseLimit } from './utils.js';\n\ncli({\n    site: 'reuters',\n    name: 'search',\n    access: 'read',\n    description: 'Reuters 路透社新闻搜索',\n    domain: 'www.reuters.com',\n    strategy: Strategy.COOKIE,\n    args: [\n        { name: 'query', required: true, positional: true, help: 'Search query' },\n        { name: 'limit', type: 'int', default: 10, help: 'Number of results (1-40)' },\n    ],\n    columns: ['rank', 'title', 'date', 'section', 'section_path', 'authors', 'url'],\n    func: async (page, kwargs) => {\n        const limit = parseLimit(kwargs.limit);\n        const query = String(kwargs.query || '').trim();\n        if (!query) {\n            throw new ArgumentError('Search query cannot be empty', 'Provide a non-empty keyword');\n        }\n        await page.goto('https://www.reuters.com');\n        await page.wait(2);\n        const result = await page.evaluate(buildSearchScript(query, limit));\n        if (result?.error) {\n            throw new CommandExecutionError(`Reuters search failed inside the page: ${result.error}`);\n        }\n        if (!result || typeof result !== 'object') {\n            throw new CommandExecutionError('Reuters search API returned an unreadable response');\n        }\n        if (isAuthStatus(result.status) || looksAuthWallText(result.textPreview)) {\n            throw new AuthRequiredError(\n                'www.reuters.com',\n                `Reuters search requires an accessible Reuters browser session or completed human verification${result.status ? ` (HTTP ${result.status})` : ''}`,\n            );\n        }\n        if (result.ok !== true) {\n            const status = Number.isFinite(result.status) && result.status > 0","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reuters/search.js#L9-L45","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait reutersSearch({ query: userInput });\n// after\nconst q = String(userInput || '').trim();\nif (!q) throw new Error('query is required');\nawait reutersSearch({ query: q });","handlingStrategy":"validation","validationCode":"function requireQuery(kwargs) {\n  const q = String(kwargs && kwargs.query || '').trim();\n  if (!q) throw new Error('query is required and must be non-empty');\n  return q;\n}\nconst query = requireQuery(userKwargs); // call before invoking the search command","typeGuard":"function hasNonEmptyQuery(kwargs) {\n  return kwargs != null && typeof kwargs.query === 'string' && kwargs.query.trim().length > 0;\n}","tryCatchPattern":"try {\n  await runCommand('reuters', 'search', { query });\n} catch (e) {\n  if (e instanceof ArgumentError && /Search query cannot be empty/.test(e.message)) {\n    console.error('Please supply a non-empty --query value');\n    process.exitCode = 2;\n  } else {\n    throw e;\n  }\n}","preventionTips":["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."],"tags":["argument-error","validation","missing-argument","reuters"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}