{"record":{"id":"17034a25e3063a72","repo":"jackwener/OpenCLI","slug":"a-search-query-is-required","errorCode":null,"errorMessage":"A search query is required.","messagePattern":"A search query is required\\.","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"warning","filePath":"clis/weixin/search.js","lineNumber":104,"sourceCode":"\ncli({\n    site: 'weixin',\n    name: 'search',\n    access: 'read',\n    description: '使用搜狗微信搜索公众号文章；如需导出正文 Markdown，请使用 weixin download 处理公众号文章链接',\n    domain: SOGOU_WEIXIN_DOMAIN,\n    strategy: Strategy.PUBLIC,\n    browser: true,\n    args: [\n        { name: 'query', positional: true, required: true, help: '搜索关键词；如需正文 Markdown，请使用 weixin download 处理公众号文章链接' },\n        { name: 'page', type: 'int', default: 1, help: '结果页码，从 1 开始' },\n        { name: 'limit', type: 'int', default: 10, help: '返回条数，最大 10' },\n    ],\n    columns: ['rank', 'page', 'title', 'url', 'summary', 'publish_time'],\n    func: async (page, kwargs) => {\n        const query = String(kwargs.query ?? '').trim();\n        if (!query) {\n            throw new ArgumentError('A search query is required.', 'Pass a non-empty keyword to search Weixin articles via Sogou.');\n        }\n\n        const pageNo = normalizePage(kwargs.page);\n        const limit = normalizeLimit(kwargs.limit);\n        const searchUrl = buildSearchUrl(query, pageNo);\n\n        let payload;\n        try {\n            await page.goto(searchUrl);\n            await page.wait(2);\n            payload = await page.evaluate(buildExtractSearchResultsEvaluate());\n        }\n        catch (error) {\n            const detail = error instanceof Error ? error.message : String(error);\n            throw new CommandExecutionError('weixin search failed while loading Sogou results', detail);\n        }\n\n        if (!payload || typeof payload !== 'object' || !Array.isArray(payload.rows)) {","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weixin/search.js#L86-L122","documentation":"This ArgumentError is thrown by the `weixin search` command when the `--query` argument is missing, empty, or whitespace-only. The CLI requires a non-empty keyword to build a Sogou Weixin search URL; without it no request can be made. It is an input-validation error raised before any browser/network work happens.","triggerScenarios":"Calling `weixin search` without `--query`, with `--query \"\"`, or with `--query \"   \"` (whitespace is trimmed then checked). Also occurs when a wrapper script passes the keyword in a variable that is unset or empty.","commonSituations":"Shell scripts where the query variable interpolates to empty (unquoted/unset env var); copy-pasted commands where --query was dropped; programmatic callers that build kwargs and omit `query` when the user submits a blank search box.","solutions":["Pass a non-empty keyword: `weixin search --query \"your keyword\"`","Check that the shell variable holding the query is set and non-empty before invoking the command","Trim the user input upstream and reject blank input in your own UI before calling the CLI"],"exampleFix":"// before\nconst query = String(kwargs.query ?? '').trim();\nif (!query) { throw new ArgumentError('A search query is required.', '...'); }\n// after (caller side)\nconst q = (process.argv.query || '').trim();\nif (!q) { console.error('usage: weixin search --query <keyword>'); process.exit(2); }\nawait cli.run(['weixin', 'search', '--query', q]);","handlingStrategy":"validation","validationCode":"const q = String(opts.query ?? '').trim();\nif (!q) throw new Error('weixin search requires a non-empty --query');","typeGuard":"function hasQuery(o) { return typeof o.query === 'string' && o.query.trim().length > 0; }","tryCatchPattern":"try { await weixinSearch({ query: q }); }\ncatch (e) { if (e.name === 'ArgumentError') { printUsage(); } else throw e; }","preventionTips":["Always pass --query explicitly in scripts","Trim and check user input before invoking","Quote shell variables: --query \"$Q\""],"tags":["argument-validation","cli","input-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}