jackwener/OpenCLI · error · ArgumentError

--${name} is required (numeric Trip.com city id, e.g. 338 fo

Error message

--${name} is required (numeric Trip.com city id, e.g. 338 for London)

What it means

parseCityId requires a numeric Trip.com city id (e.g. 338 for London) and throws this when the argument is missing, null, or whitespace-only. City ids are Trip.com-internal numeric identifiers, distinct from IATA codes.

Source

Thrown at clis/trip/utils.js:244

    const detect = () => {
      if (/captcha|verify you are human|security check/i.test(document.body?.innerText || '')) return 'captcha';
      if (document.querySelector('.result-item')) return 'content';
      return null;
    };
    const found = detect();
    if (found) return resolve(found);
    const observer = new MutationObserver(() => {
      const result = detect();
      if (result) { observer.disconnect(); resolve(result); }
    });
    observer.observe(document.documentElement, { childList: true, subtree: true });
    setTimeout(() => { observer.disconnect(); resolve('timeout'); }, 12000);
  })
`;

export function parseCityId(name, raw) {
    if (raw === undefined || raw === null || String(raw).trim() === '') {
        throw new ArgumentError(`--${name} is required (numeric Trip.com city id, e.g. 338 for London)`);
    }
    const value = String(raw).trim();
    if (!/^\d+$/.test(value)) {
        throw new ArgumentError(`--${name} must be a numeric Trip.com city id, got ${JSON.stringify(raw)}`);
    }
    return value;
}

export function buildHotelSearchUrl(cityId, checkin, checkout) {
    const params = new URLSearchParams({
        city: cityId,
        checkin,
        checkout,
        locale: 'en_US',
        curr: 'USD',
    });
    return `https://www.trip.com/hotels/list?${params.toString()}`;
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Supply the numeric id, e.g. --city-id 338
  2. Look up the city id via the Trip.com city/search listing if unknown (London is 338)
  3. Do not pass an IATA code or city name here — the id is numeric
  4. If the value comes from a variable/config, ensure it is set and non-empty

Example fix

// before
clis-trip hotels --city-id LON --checkin 2026-10-01
// after
clis-trip hotels --city-id 338 --checkin 2026-10-01
Defensive patterns

Strategy: validation

Validate before calling

if (cityId === undefined || cityId === null || String(cityId).trim() === '') {
  throw new Error('--city-id is required (numeric Trip.com city id)');
}

Type guard

function isProvided(v) {
  return v !== undefined && v !== null && String(v).trim() !== '';
}

Try / catch

try {
  runTripCli(['hotels', '--city-id', cityId, '--checkin', ci, '--checkout', co]);
} catch (err) {
  if (err instanceof ArgumentError && /--city-id is required/.test(err.message)) {
    console.error('Provide a numeric Trip.com city id (run the city search first, e.g. 338 for London).');
    process.exitCode = 2;
  } else throw err;
}

Prevention

When it happens

Trigger: Calling cityId (which delegates to parseCityId) without the flag, with --city-id '', or with an unset variable interpolated as empty.

Common situations: User passes 'LON' (IATA code) in the wrong field but omits the actual city-id flag; script variables not exported; config file key missing so the value resolves to empty.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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