jackwener/OpenCLI · error · ArgumentError
Invalid BOSS city: ${input}
Error message
Invalid BOSS city: ${input} What it means
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.
Source
Thrown at clis/boss/search.js:65
'人工智能': '100901', '大数据': '100902', '金融': '100101',
'教育培训': '100200', '医疗健康': '100300',
};
const JOB_TYPE_MAP = {
'不限': '0', '全职': '1901', '实习': '1902', '兼职': '1903',
};
const JOB_TYPE_CODES = new Set(Object.values(JOB_TYPE_MAP));
function resolveCity(input) {
if (!input)
return '101010100';
if (/^\d+$/.test(input))
return input;
if (CITY_CODES[input])
return CITY_CODES[input];
for (const [name, code] of Object.entries(CITY_CODES)) {
if (name.includes(input))
return code;
}
throw new ArgumentError(`Invalid BOSS city: ${input}`, 'Use a supported city name or a numeric BOSS city code');
}
function resolveMap(input, map) {
if (!input)
return '';
if (map[input] !== undefined)
return map[input];
for (const [key, val] of Object.entries(map)) {
if (key.includes(input))
return val;
}
return input;
}
function resolveJobType(input) {
if (!input)
return '';
if (JOB_TYPE_MAP[input] !== undefined)
return JOB_TYPE_MAP[input];
if (JOB_TYPE_CODES.has(input))View on GitHub (pinned to 49907e53dc)
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
Example fix
// before
await cli('boss', 'search', { city: 'shanghai' });
// after
await cli('boss', 'search', { city: '上海' });
// or
await cli('boss', 'search', { city: '101020100' }); Defensive patterns
Strategy: validation
Validate before calling
const SUPPORTED_CITIES = ['全国','北京','上海','广州','深圳','杭州','成都','南京','武汉','西安'];
function isValidCity(city) {
return /^\d+$/.test(city) || SUPPORTED_CITIES.some(n => n.includes(city));
}
if (!isValidCity(input)) throw new Error(`unsupported BOSS city: ${input}`); Type guard
const isBossCity = (c) => typeof c === 'string' && (/^\d+$/.test(c) || Object.keys(CITY_CODES).some(n => n.includes(c)));
Try / catch
try {
const jobs = await cli('boss', 'search', { city: input });
} catch (e) {
if (String(e.message).startsWith('Invalid BOSS city')) {
return cli('boss', 'search', { city: '全国' }); // fallback
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Invalid jobType: ${input}
- boss ${name} must be a positive integer
- <train-no> must not be empty
- <train-no> "${trainNo}" does not look like a 12306 internal
- --from station must not be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/0c94307fd2d60cde.
Report an issue: GitHub.