{"record":{"id":"5af2bf19510f4cfd","repo":"jackwener/OpenCLI","slug":"unknown-12306-station-trimmed","errorCode":null,"errorMessage":"Unknown 12306 station \"${trimmed}\"","messagePattern":"Unknown 12306 station \"(.+?)\"","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/12306/utils.js","lineNumber":89,"sourceCode":" * (`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) {\n        throw new ArgumentError(`date \"${value}\" is not a real calendar date`);\n    }\n    return value;\n}\n\nexport function normalizeLimit(value, defaultValue, max) {\n    if (value === undefined || value === null || value === '') return defaultValue;\n    const n = Number(value);\n    if (!Number.isInteger(n) || n < 1) {","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/12306/utils.js#L71-L107","documentation":"resolveStation() exhausted all lookup strategies — exact code, exact Chinese name, pinyin, and abbreviation — and could not match the input to any station in the bundle. Thrown as ArgumentError with a hint suggesting the accepted input formats (Chinese name, 3-4 letter telecode, or full pinyin).","triggerScenarios":"Calling fromStation()/toStation() with a value that matches no station by name, pinyin, abbr, short, or code: misspelled names, partial names ('上海' works only if exact), partial pinyin ('shanghongqiao'), or non-station strings like 'Beijing'.","commonSituations":"Users typing English station names, partial pinyin abbreviations that don't match the abbr/short fields, or extra whitespace/characters around the name.","solutions":["Use the exact Chinese station name, e.g. '上海虹桥'","Use the official 3-4 letter telecode, e.g. 'AOH'","Use the station's full pinyin without spaces, e.g. 'shanghaihongqiao'","Inspect the station bundle list to find the exact name/pinyin/abbr string the library expects"],"exampleFix":"// before\nconst stn = await toStation(ctx, 'shanghai hongqiao');\n// after\nconst stn = await toStation(ctx, 'shanghaihongqiao'); // no spaces","handlingStrategy":"validation","validationCode":"function isKnownStation(input, stations) {\n  const t = String(input ?? '').trim();\n  const l = t.toLowerCase();\n  return stations.some((s) => s.code === t || s.name === t || s.pinyin === l || s.abbr === l || s.short === l);\n}\nif (!isKnownStation('上海虹桥', stations)) throw new Error('unknown station');","typeGuard":null,"tryCatchPattern":"try {\n  const stn = resolveStation(stations, input);\n} catch (e) {\n  if (e instanceof ArgumentError && e.hint) {\n    console.error(`${e.message}\\nHint: ${e.hint}`);\n  } else throw e;\n}","preventionTips":["Always pass the exact Chinese station name or full pinyin","Trim whitespace and normalize case before calling","Offer users a station autocomplete backed by the station bundle","Don't assume English names or partial pinyin will resolve"],"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"}