jackwener/OpenCLI · error · ArgumentError

--${name} is required (numeric Trip.com hotel id, discover v

Error message

--${name} is required (numeric Trip.com hotel id, discover via the hotels list)

What it means

parseHotelId requires a numeric Trip.com hotel id and throws this when the argument is missing, null, or whitespace-only. Hotel ids should be discovered via the hotels list command, as the message indicates.

Source

Thrown at clis/trip/utils.js:319

    const detect = () => {
      if (/captcha|verify you are human|security check/i.test(document.body?.innerText || '')) return 'captcha';
      if (document.querySelector('.hotel-card')) 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 parseHotelId(name, raw) {
    if (raw === undefined || raw === null || String(raw).trim() === '') {
        throw new ArgumentError(`--${name} is required (numeric Trip.com hotel id, discover via the hotels list)`);
    }
    const value = String(raw).trim();
    if (!/^\d+$/.test(value)) {
        throw new ArgumentError(`--${name} must be a numeric Trip.com hotel id, got ${JSON.stringify(raw)}`);
    }
    return value;
}

export function buildHotelDetailUrl(hotelId) {
    const params = new URLSearchParams({ hotelId, locale: 'en_US', curr: 'USD' });
    return `https://www.trip.com/hotels/detail/?${params.toString()}`;
}

/**
 * Browser-context IIFE that projects the single-hotel profile from
 * `__NEXT_DATA__.props.pageProps.hotelDetailResponse` (the same SSR shape the
 * mainland `ctrip hotel` detail uses). Rating sub-scores, popular amenities, and
 * the check-in/out policy are each joined into one string so the profile stays a

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Supply the numeric hotel id, e.g. --hotel-id 12345678
  2. Run the hotels list command first (with a valid --city-id and dates) to discover hotel ids
  3. Ensure the variable holding the id from the list step is actually set before invoking
  4. Do not pass a hotel name — the id must be numeric

Example fix

// before
clis-trip hotel-detail --hotel-id
// after
clis-trip hotels --city-id 338 --checkin 2026-10-01 --checkout 2026-10-05
clis-trip hotel-detail --hotel-id 12345678
Defensive patterns

Strategy: validation

Validate before calling

if (hotelId === undefined || hotelId === null || String(hotelId).trim() === '') {
  throw new Error('--hotel-id is required (numeric Trip.com hotel id, discover via the hotels list)');
}

Type guard

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

Try / catch

try {
  runTripCli(['hotel-detail', '--hotel-id', hotelId]);
} catch (err) {
  if (err instanceof ArgumentError && /--hotel-id is required/.test(err.message)) {
    console.error('Run the hotels list first to get a numeric hotel id, then pass --hotel-id <digits>.');
    process.exitCode = 2;
  } else throw err;
}

Prevention

When it happens

Trigger: Calling hotelId (which delegates to parseHotelId) without the flag, with --hotel-id '', or with an unset variable that yields an empty string.

Common situations: User skips the discovery step and runs a hotel-detail command directly; script reads an empty config key; the previous hotels-list call failed silently so no id was captured to pass along.

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/a4edaf3ff9d86e9c. Report an issue: GitHub.