{"record":{"id":"0c94307fd2d60cde","repo":"jackwener/OpenCLI","slug":"invalid-boss-city-input","errorCode":null,"errorMessage":"Invalid BOSS city: ${input}","messagePattern":"Invalid BOSS city: (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/boss/search.js","lineNumber":65,"sourceCode":"    '人工智能': '100901', '大数据': '100902', '金融': '100101',\n    '教育培训': '100200', '医疗健康': '100300',\n};\nconst JOB_TYPE_MAP = {\n    '不限': '0', '全职': '1901', '实习': '1902', '兼职': '1903',\n};\nconst JOB_TYPE_CODES = new Set(Object.values(JOB_TYPE_MAP));\nfunction resolveCity(input) {\n    if (!input)\n        return '101010100';\n    if (/^\\d+$/.test(input))\n        return input;\n    if (CITY_CODES[input])\n        return CITY_CODES[input];\n    for (const [name, code] of Object.entries(CITY_CODES)) {\n        if (name.includes(input))\n            return code;\n    }\n    throw new ArgumentError(`Invalid BOSS city: ${input}`, 'Use a supported city name or a numeric BOSS city code');\n}\nfunction resolveMap(input, map) {\n    if (!input)\n        return '';\n    if (map[input] !== undefined)\n        return map[input];\n    for (const [key, val] of Object.entries(map)) {\n        if (key.includes(input))\n            return val;\n    }\n    return input;\n}\nfunction resolveJobType(input) {\n    if (!input)\n        return '';\n    if (JOB_TYPE_MAP[input] !== undefined)\n        return JOB_TYPE_MAP[input];\n    if (JOB_TYPE_CODES.has(input))","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/boss/search.js#L47-L83","documentation":"resolveCity validates the city argument for BOSS search before building the query URL. It accepts exact CITY_CODES keys, a substring match against city names, or a purely numeric BOSS city code; anything else raises this ArgumentError with a hint to use a supported name or numeric code.","triggerScenarios":"Passing city values like 'shanghai' (English), '北上广' (multi-city shorthand), misspelled names ('杭州湾'), or a non-numeric/non-listed token to the city parameter of boss search.","commonSituations":"Developers using pinyin or English city names; assuming any Chinese city is supported (the map covers ~40 major cities); typos in Chinese characters; passing province names instead of city names.","solutions":["Use one of the supported Chinese city names exactly as listed (e.g. '北京', '上海', '深圳')","Or pass the numeric BOSS city code directly if you have it (resolveCity accepts any /^\\d+$/ string)","Check the CITY_CODES map in clis/boss/search.js for the exact supported names","Fix typos — the substring match needs the input to appear inside a supported name","Extend CITY_CODES with the missing city's BOSS code if you need an unlisted city"],"exampleFix":"// before\nawait cli('boss', 'search', { city: 'shanghai' });\n// after\nawait cli('boss', 'search', { city: '上海' });\n// or\nawait cli('boss', 'search', { city: '101020100' });","handlingStrategy":"validation","validationCode":"const SUPPORTED_CITIES = ['全国','北京','上海','广州','深圳','杭州','成都','南京','武汉','西安'];\nfunction isValidCity(city) {\n  return /^\\d+$/.test(city) || SUPPORTED_CITIES.some(n => n.includes(city));\n}\nif (!isValidCity(input)) throw new Error(`unsupported BOSS city: ${input}`);","typeGuard":"const isBossCity = (c) => typeof c === 'string' && (/^\\d+$/.test(c) || Object.keys(CITY_CODES).some(n => n.includes(c)));","tryCatchPattern":"try {\n  const jobs = await cli('boss', 'search', { city: input });\n} catch (e) {\n  if (String(e.message).startsWith('Invalid BOSS city')) {\n    return cli('boss', 'search', { city: '全国' }); // fallback\n  }\n  throw e;\n}","preventionTips":["Use exact Chinese city names from the CITY_CODES map","Prefer numeric BOSS city codes for stability","Validate city input at the CLI/config boundary","Extend CITY_CODES deliberately for new cities rather than guessing names"],"tags":["argument-validation","input-mapping","boss-zhipin"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}