jackwener/OpenCLI · error · ArgumentError

unknown city '${cityArg}'. pass a numeric cityId, a pinyin s

Error message

unknown city '${cityArg}'. pass a numeric cityId, a pinyin slug (e.g. shantou), a Chinese name listed on dianping.com/citylist, or one of: ${known}

What it means

ArgumentError from resolveCityIdAsync when the --city argument is a Chinese city name that is not found in the static CITY_ID map and lookupPinyinFromCitylist could not map it either (no pinyin derived). The library needs a numeric cityId or pinyin slug to build Dianping search URLs. Thrown because the Chinese name could not be translated to a pinyin slug.

Source

Thrown at clis/dianping/cityResolver.js:76

    // back to dynamic resolution rather than surface the error to the user.
    try {
        const staticId = resolveCityId(raw);
        if (staticId != null) return staticId;
    } catch (err) {
        if (err?.code !== 'ARGUMENT') throw err;
    }

    if (RESOLVE_CACHE.has(lowered)) return RESOLVE_CACHE.get(lowered);
    if (RESOLVE_CACHE.has(raw)) return RESOLVE_CACHE.get(raw);

    let pinyin = null;
    if (PINYIN_RE.test(lowered)) {
        pinyin = lowered;
    } else if (CHINESE_RE.test(raw)) {
        pinyin = await lookupPinyinFromCitylist(page, raw);
        if (!pinyin) {
            const known = Object.keys(CITY_ID).filter((k) => /^[a-z]+$/.test(k)).join(', ');
            throw new ArgumentError(
                'city',
                `unknown city '${cityArg}'. pass a numeric cityId, a pinyin slug (e.g. shantou), `
                + `a Chinese name listed on dianping.com/citylist, or one of: ${known}`,
            );
        }
    } else {
        const known = Object.keys(CITY_ID).filter((k) => /^[a-z]+$/.test(k)).join(', ');
        throw new ArgumentError(
            'city',
            `unknown city '${cityArg}'. pass a numeric cityId, a pinyin slug (e.g. shantou), `
            + `a Chinese name listed on dianping.com/citylist, or one of: ${known}`,
        );
    }

    const cityId = await fetchCityIdByPinyin(page, pinyin);
    if (!cityId) {
        throw new CommandExecutionError(
            `dianping could not resolve cityId for '${cityArg}' (pinyin=${pinyin}); `

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass the numeric cityId directly if you know it (e.g. city=108) — skips name resolution entirely.
  2. Use the pinyin slug form instead of Chinese characters, e.g. city='chongqing'.
  3. Check the error's known list (lowercase CITY_ID keys) and use one of the supported slugs.
  4. If the Chinese name should work, verify dianping.com/citylist renders (may have failed — see the citylist-empty error) and that the name matches exactly what the site lists.

Example fix

// before
await cli.dianping.search({ keyword: '火锅', city: '重庆' });
// after
await cli.dianping.search({ keyword: '火锅', city: 'chongqing' }); // or a numeric cityId
Defensive patterns

Strategy: validation

Validate before calling

function resolveCityArg(city) {
  if (/^\d+$/.test(city)) return city;
  if (/^[a-z]+$/.test(city)) return city; // pinyin slug
  throw new Error(`pass a numeric cityId or pinyin slug, not '${city}'`);
}

Type guard

function isKnownCity(city, map) { return typeof city === 'string' && ( /^\d+$/.test(city) || /^[a-z]+$/.test(city) || city in map ); }

Try / catch

try { await cli.dianping.search({ keyword, city }); }
catch (e) { if (e.name === 'ArgumentError' && e.field === 'city') { console.error('use cityId or pinyin slug, e.g. shantou'); process.exitCode = 2; } else throw e; }

Prevention

When it happens

Trigger: Passing city='重庆' (or any Chinese name) where CHINESE_RE matches but lookupPinyinFromCitylist returns no pinyin — either the name is absent from dianping.com/citylist or the citylist scrape failed, and the name is not a key of the static CITY_ID map.

Common situations: Typo or alternate/old name for a Chinese city (e.g.使用简称 or 旧称); citylist page failed to render so the online lookup couldn't run; using a district name not listed as a top-level city.

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


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/e460259339d15fe5. Report an issue: GitHub.