jackwener/OpenCLI · error · ArgumentError
Unknown 12306 station telecode "${trimmed}"
Error message
Unknown 12306 station telecode "${trimmed}" What it means
resolveStation() looked up a station by 3-4 letter telecode (matching STATION_CODE_RE) but no station in the loaded station list has that code. 12306 identifies stations by internal telecodes (e.g. AOH for 上海虹桥), and this library only accepts codes present in its station bundle. Thrown as ArgumentError to signal bad user input.
Source
Thrown at clis/12306/utils.js:80
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}"`);
}
const [y, m, d] = value.split('-').map(Number);
const date = new Date(Date.UTC(y, m - 1, d));
if (date.getUTCFullYear() !== y || date.getUTCMonth() !== m - 1 || date.getUTCDate() !== d) {View on GitHub (pinned to 49907e53dc)
Solutions
- Verify the telecode against 12306's station list (e.g. query the stations command/bundle) and correct the typo
- Switch to passing the station's Chinese name (e.g. '上海虹桥') or full pinyin ('shanghaihongqiao'), which resolveStation also accepts
- Confirm the station actually exists in the fetched station bundle; outdated or filtered bundles may omit stations
Example fix
// before const stn = await fromStation(ctx, 'AHO'); // after const stn = await fromStation(ctx, 'AOH'); // correct telecode for 上海虹桥
Defensive patterns
Strategy: validation
Validate before calling
const TELECODE_RE = /^[A-Z]{3,4}$/;
function looksLikeTelecode(input, stations) {
const t = String(input ?? '').trim();
return !TELECODE_RE.test(t) || stations.some((s) => s.code === t);
}
if (!looksLikeTelecode('AOH', stations)) throw new Error('unknown telecode'); Try / catch
try {
const stn = resolveStation(stations, input);
} catch (e) {
if (e instanceof ArgumentError && /telecode/.test(e.message)) {
console.error(`Telecode "${input}" not found; use the station's Chinese name instead.`);
} else throw e;
} Prevention
- Keep a copy of the official 12306 telecode table for reference
- Prefer Chinese names over telecodes in user-facing inputs
- Never hand-type telecodes; copy them from the station bundle
- Watch for 0/O and I/1 confusion in codes
When it happens
Trigger: Calling fromStation()/toStation() with a string that looks like a telecode (3-4 letters, matches STATION_CODE_RE) but is not a real 12306 code — a typo like 'AHO' instead of 'AOH', an invented code, or a code from a different railway system.
Common situations: Developers hard-coding telecodes copied from an old table, mixing up visually similar codes (0/O, I/1), or using IATA-style city codes that 12306 does not use.
Related errors
- Unknown 12306 station "${trimmed}"
- date must be YYYY-MM-DD, got "${value}"
- date "${value}" is not a real calendar date
- limit must be a positive integer (1-${max})
- limit must be <= ${max}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/1ae4833f749d43d1.
Report an issue: GitHub.