jackwener/OpenCLI · error · ArgumentError
keyword must not be empty
Error message
keyword must not be empty
What it means
The `12306 stations` command takes a required positional `keyword` used to search station name (Chinese substring), telecode, pinyin, abbreviation, short form, or city. This ArgumentError is thrown when the keyword is missing or empty after trimming — a client-side guard thrown before any network call.
Source
Thrown at clis/12306/stations.js:28
const MAX_LIMIT = 50;
cli({
site: '12306',
name: 'stations',
access: 'read',
description: 'Search 12306 (China Railway) stations by Chinese name, telecode, or pinyin keyword',
domain: 'kyfw.12306.cn',
strategy: Strategy.PUBLIC,
browser: false,
args: [
{ name: 'keyword', positional: true, required: true, help: 'Chinese substring (上海), telecode (AOH), or pinyin (shanghai)' },
{ name: 'limit', type: 'int', default: 20, help: `Maximum results (1-${MAX_LIMIT})` },
],
columns: ['name', 'code', 'pinyin', 'abbr', 'city'],
func: async (kwargs) => {
const keyword = String(kwargs.keyword ?? '').trim();
if (!keyword) throw new ArgumentError('keyword must not be empty');
const limit = normalizeLimit(kwargs.limit, 20, MAX_LIMIT);
const stations = await fetchStationBundle();
const lower = keyword.toLowerCase();
const matches = stations.filter((s) =>
s.name.includes(keyword)
|| s.code === keyword.toUpperCase()
|| s.pinyin.includes(lower)
|| s.abbr.includes(lower)
|| s.short.includes(lower)
|| s.city.includes(keyword),
);
if (matches.length === 0) {
throw new EmptyResultError(`No 12306 stations match "${keyword}"`);
}
return matches.slice(0, limit).map((s) => ({
name: s.name,
code: s.code,View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a non-empty keyword: `12306 stations 上海`, `12306 stations AOH`, or `12306 stations shanghai`.
- Guard the variable before invoking: `[ -n "$KW" ] && 12306 stations "$KW"`.
- Quote the keyword to avoid the shell splitting it into separate arguments.
Example fix
// before 12306 stations # missing keyword // after 12306 stations 上海
Defensive patterns
Strategy: validation
Validate before calling
const keyword = String(process.argv[3] ?? '').trim();
if (!keyword) { console.error('Usage: 12306 stations <keyword>'); process.exit(2); } Try / catch
try {
const stations = await stationsCmd({ keyword });
} catch (e) {
if (e instanceof ArgumentError && /keyword must not be empty/.test(e.message)) {
console.error('Provide a search keyword: Chinese substring, telecode, or pinyin.');
} else throw e;
} Prevention
- Always pass a quoted positional keyword: `12306 stations "上海"`.
- Guard unset shell variables before invocation.
- Remember keyword is positional and required — flags won't satisfy it.
When it happens
Trigger: Running `12306 stations` with no positional argument, `12306 stations ""`, or `12306 stations " "`; scripts where the keyword variable is unset/empty.
Common situations: Forgetting the positional argument (it's required:true); empty variable interpolation in shell scripts; passing the flag value to the wrong slot so keyword is undefined.
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
- <from> station must not be empty
- <to> station must not be empty
- who 不能为空
- key is required
- ${label} is required (YYYY-MM-DD)
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/276d2ee36df13822.
Report an issue: GitHub.