jackwener/OpenCLI · error · ArgumentError
keyword
Error message
keyword
What it means
ArgumentError thrown by the dianping search command when the required --keyword argument is missing or an empty/whitespace-only string. The library validates keyword before doing any network work since Dianping search requires a non-empty query term.
Source
Thrown at clis/dianping/search.js:107
return { ok: true, rows };
}
cli({
site: 'dianping',
name: 'search',
access: 'read',
description: '大众点评店铺搜索(按关键词 + 城市)',
domain: 'www.dianping.com',
strategy: Strategy.COOKIE,
args: [
{ name: 'keyword', required: true, positional: true, help: '搜索关键词,例如 "火锅"' },
{ name: 'city', help: '城市名(北京/上海/汕头/beijing/shantou/...)或 cityId 数字。未在静态表中的城市会通过 dianping.com 在线解析。不传则使用 cookie 默认城市' },
{ name: 'limit', type: 'int', default: 15, help: '返回的店铺数量(最多 15,dianping 单页固定 15 条)' },
],
columns: SEARCH_COLUMNS,
func: async (page, kwargs) => {
const keyword = String(kwargs.keyword || '').trim();
if (!keyword) throw new ArgumentError('keyword', 'must be a non-empty string');
const limit = requireSearchLimit(kwargs.limit);
const cityId = await wrapDianpingStep(
'city resolve',
() => resolveCityIdAsync(page, kwargs.city),
);
const path = cityId
? `/search/keyword/${cityId}/0_${encodeURIComponent(keyword)}`
: `/search/keyword/0/0_${encodeURIComponent(keyword)}`;
const url = `https://www.dianping.com${path}`;
await wrapDianpingStep(`search "${keyword}" navigation`, async () => {
await page.goto(url);
await page.wait(2);
});
const result = await wrapDianpingStep(View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a non-empty keyword: dianping search --keyword "火锅".
- Check that your wrapper/script maps the search term to the correct `keyword` key in kwargs.
- Trim/validate the term before invoking: if (!kw.trim()) skip or prompt for input.
- If shell variables supply the value, quote them and guard against empty expansion.
Example fix
// before
const kw = process.env.Q; await cli.dianping.search({ keyword: kw }); // Q empty → throws
// after
const kw = (process.env.Q || '').trim();
if (!kw) throw new Error('set Q to a search term');
await cli.dianping.search({ keyword: kw }); Defensive patterns
Strategy: validation
Validate before calling
const keyword = String(process.argv[kwIdx] || '').trim();
if (!keyword) { console.error('--keyword is required and must be non-empty'); process.exit(2); } Type guard
function hasKeyword(k) { return typeof k === 'string' && k.trim().length > 0; } Try / catch
try { await cli.dianping.search({ keyword, city }); }
catch (e) { if (e.name === 'ArgumentError' && e.field === 'keyword') { console.error('usage: dianping search --keyword "<term>"'); process.exitCode = 2; } else throw e; } Prevention
- Always pass --keyword explicitly and quote shell values.
- Trim and check emptiness of the term in wrappers before invoking.
- Use the correct kwarg name (`keyword`), not query/q.
- Fail fast in scripts when the upstream term variable is empty.
When it happens
Trigger: Calling the dianping search func with kwargs lacking keyword, or keyword='' / keyword=' ' (String(kwargs.keyword||'').trim() yields empty), e.g. `dianping search --city shanghai` with no --keyword, or passing --keyword "" from a script.
Common situations: CLI invocation missing the --keyword flag; building kwargs programmatically where an upstream variable was empty; shell quoting swallowing the value (e.g. --keyword "$Q" with Q empty); passing the term under a wrong key like 'query' or 'q'.
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
- keyword must not be empty
- <from> station must not be empty
- <to> station must not be empty
- who 不能为空
- key is required
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/d97ecc3b73d0e15a.
Report an issue: GitHub.