jackwener/OpenCLI · error · ArgumentError

station must not be empty

Error message

station must not be empty

What it means

ArgumentError from resolveStation when the station input is missing, null, or whitespace-only after trimming. resolveStation is the shared identifier-to-telecode resolver used for both from and to stations; an empty value cannot be matched against the bundle, so it fails fast before the lookup.

Source

Thrown at clis/12306/utils.js:76

            city: parts[7] || '',
        });
    }
    if (stations.length === 0) {
        throw new CommandExecutionError('Failed to parse 12306 station_name.js: no station records found');
    }
    return stations;
}

/**
 * Resolve a user-supplied station identifier to a telecode.
 *
 * Accepts Chinese name (`上海虹桥`), telecode (`AOH`), pinyin
 * (`shanghaihongqiao`), short alias (`shh`), or city name with a
 * preference for the city's main station.
 */
export function resolveStation(stations, input) {
    const trimmed = String(input ?? '').trim();
    if (!trimmed) throw new ArgumentError('station must not be empty');
    if (STATION_CODE_RE.test(trimmed)) {
        const exact = stations.find((s) => s.code === trimmed);
        if (exact) return exact;
        throw new ArgumentError(`Unknown 12306 station telecode "${trimmed}"`);
    }
    const lower = trimmed.toLowerCase();
    const exactName = stations.find((s) => s.name === trimmed);
    if (exactName) return exactName;
    const exactPinyin = stations.find((s) => s.pinyin === lower);
    if (exactPinyin) return exactPinyin;
    const exactAbbr = stations.find((s) => s.abbr === lower || s.short === lower);
    if (exactAbbr) return exactAbbr;
    throw new ArgumentError(`Unknown 12306 station "${trimmed}"`, 'Try the Chinese name (上海虹桥), the 3-4 letter telecode (AOH), or full pinyin (shanghaihongqiao).');
}

export function validateDate(value) {
    if (!DATE_RE.test(String(value ?? ''))) {
        throw new ArgumentError(`date must be YYYY-MM-DD, got "${value}"`);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Ensure the station string is non-empty before calling: Chinese name, telecode, pinyin, or short alias.
  2. Validate/skip blank rows in batch scripts before resolving.
  3. Fix delimiter-based parsing so both origin and destination parts are captured.
  4. Reuse the command-level ArgumentError message to surface which argument was blank in your wrapper.

Example fix

// before
const toStation = resolveStation(stations, parts[1] ?? ''); // parts[1] may be undefined
// after
if (!parts[1]?.trim()) throw new Error(`row ${i}: destination station missing`);
const toStation = resolveStation(stations, parts[1]);
Defensive patterns

Strategy: validation

Validate before calling

if (!input || !String(input).trim()) {
  throw new Error('station identifier required (Chinese name, telecode, pinyin, or alias)');
}

Type guard

function hasStationInput(v) {
  return typeof v === 'string' && v.trim().length > 0;
}

Try / catch

try {
  const station = resolveStation(stations, input);
} catch (e) {
  if (e.name === 'ArgumentError' && /station must not be empty/.test(e.message)) {
    console.error('Blank station input — check your delimiter parsing or config values.');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling resolveStation (directly or via the trains command internals) with undefined/null/'' input — e.g. `resolveStation(stations, '')`, or a caller that already trimmed its argument to empty before delegating.

Common situations: Library callers building station lookup utilities and passing an unset variable; splitting user input (e.g. "北京→上海" on a wrong delimiter) yielding an empty part; CSV/script rows with a blank station column.

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


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/75cff95ebaad8005. Report an issue: GitHub.