jackwener/OpenCLI · warning · ArgumentError
A search query is required.
Error message
A search query is required.
What it means
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.
Source
Thrown at clis/weixin/search.js:104
cli({
site: 'weixin',
name: 'search',
access: 'read',
description: '使用搜狗微信搜索公众号文章;如需导出正文 Markdown,请使用 weixin download 处理公众号文章链接',
domain: SOGOU_WEIXIN_DOMAIN,
strategy: Strategy.PUBLIC,
browser: true,
args: [
{ name: 'query', positional: true, required: true, help: '搜索关键词;如需正文 Markdown,请使用 weixin download 处理公众号文章链接' },
{ name: 'page', type: 'int', default: 1, help: '结果页码,从 1 开始' },
{ name: 'limit', type: 'int', default: 10, help: '返回条数,最大 10' },
],
columns: ['rank', 'page', 'title', 'url', 'summary', 'publish_time'],
func: async (page, kwargs) => {
const query = String(kwargs.query ?? '').trim();
if (!query) {
throw new ArgumentError('A search query is required.', 'Pass a non-empty keyword to search Weixin articles via Sogou.');
}
const pageNo = normalizePage(kwargs.page);
const limit = normalizeLimit(kwargs.limit);
const searchUrl = buildSearchUrl(query, pageNo);
let payload;
try {
await page.goto(searchUrl);
await page.wait(2);
payload = await page.evaluate(buildExtractSearchResultsEvaluate());
}
catch (error) {
const detail = error instanceof Error ? error.message : String(error);
throw new CommandExecutionError('weixin search failed while loading Sogou results', detail);
}
if (!payload || typeof payload !== 'object' || !Array.isArray(payload.rows)) {View on GitHub (pinned to 49907e53dc)
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
Example fix
// before
const query = String(kwargs.query ?? '').trim();
if (!query) { throw new ArgumentError('A search query is required.', '...'); }
// after (caller side)
const q = (process.argv.query || '').trim();
if (!q) { console.error('usage: weixin search --query <keyword>'); process.exit(2); }
await cli.run(['weixin', 'search', '--query', q]); Defensive patterns
Strategy: validation
Validate before calling
const q = String(opts.query ?? '').trim();
if (!q) throw new Error('weixin search requires a non-empty --query'); Type guard
function hasQuery(o) { return typeof o.query === 'string' && o.query.trim().length > 0; } Try / catch
try { await weixinSearch({ query: q }); }
catch (e) { if (e.name === 'ArgumentError') { printUsage(); } else throw e; } Prevention
- Always pass --query explicitly in scripts
- Trim and check user input before invoking
- Quote shell variables: --query "$Q"
When it happens
Trigger: 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.
Common situations: 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.
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
- ${label} must be a non-negative integer, got ${JSON.stringif
- limit must be a positive integer
- bilibili comment ${label} must be a positive integer
- bilibili comment message cannot be empty
- bilibili unfollow target cannot be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/17034a25e3063a72.
Report an issue: GitHub.