{"record":{"id":"1ae4833f749d43d1","repo":"jackwener/OpenCLI","slug":"unknown-12306-station-telecode-trimmed","errorCode":null,"errorMessage":"Unknown 12306 station telecode \"${trimmed}\"","messagePattern":"Unknown 12306 station telecode \"(.+?)\"","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/12306/utils.js","lineNumber":80,"sourceCode":"        throw new CommandExecutionError('Failed to parse 12306 station_name.js: no station records found');\n    }\n    return stations;\n}\n\n/**\n * Resolve a user-supplied station identifier to a telecode.\n *\n * Accepts Chinese name (`上海虹桥`), telecode (`AOH`), pinyin\n * (`shanghaihongqiao`), short alias (`shh`), or city name with a\n * preference for the city's main station.\n */\nexport function resolveStation(stations, input) {\n    const trimmed = String(input ?? '').trim();\n    if (!trimmed) throw new ArgumentError('station must not be empty');\n    if (STATION_CODE_RE.test(trimmed)) {\n        const exact = stations.find((s) => s.code === trimmed);\n        if (exact) return exact;\n        throw new ArgumentError(`Unknown 12306 station telecode \"${trimmed}\"`);\n    }\n    const lower = trimmed.toLowerCase();\n    const exactName = stations.find((s) => s.name === trimmed);\n    if (exactName) return exactName;\n    const exactPinyin = stations.find((s) => s.pinyin === lower);\n    if (exactPinyin) return exactPinyin;\n    const exactAbbr = stations.find((s) => s.abbr === lower || s.short === lower);\n    if (exactAbbr) return exactAbbr;\n    throw new ArgumentError(`Unknown 12306 station \"${trimmed}\"`, 'Try the Chinese name (上海虹桥), the 3-4 letter telecode (AOH), or full pinyin (shanghaihongqiao).');\n}\n\nexport function validateDate(value) {\n    if (!DATE_RE.test(String(value ?? ''))) {\n        throw new ArgumentError(`date must be YYYY-MM-DD, got \"${value}\"`);\n    }\n    const [y, m, d] = value.split('-').map(Number);\n    const date = new Date(Date.UTC(y, m - 1, d));\n    if (date.getUTCFullYear() !== y || date.getUTCMonth() !== m - 1 || date.getUTCDate() !== d) {","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/12306/utils.js#L62-L98","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nconst stn = await fromStation(ctx, 'AHO');\n// after\nconst stn = await fromStation(ctx, 'AOH'); // correct telecode for 上海虹桥","handlingStrategy":"validation","validationCode":"const TELECODE_RE = /^[A-Z]{3,4}$/;\nfunction looksLikeTelecode(input, stations) {\n  const t = String(input ?? '').trim();\n  return !TELECODE_RE.test(t) || stations.some((s) => s.code === t);\n}\nif (!looksLikeTelecode('AOH', stations)) throw new Error('unknown telecode');","typeGuard":null,"tryCatchPattern":"try {\n  const stn = resolveStation(stations, input);\n} catch (e) {\n  if (e instanceof ArgumentError && /telecode/.test(e.message)) {\n    console.error(`Telecode \"${input}\" not found; use the station's Chinese name instead.`);\n  } else throw e;\n}","preventionTips":["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"],"tags":["input-validation","station-lookup","argument-error"],"backgroundTag":"invalid-station-code","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}