jackwener/OpenCLI · error · ArgumentError
hotel id is required (numeric id from `ctrip hotel-suggest`,
Error message
hotel id is required (numeric id from `ctrip hotel-suggest`, e.g. 375539)
What it means
parseHotelId requires a numeric Ctrip hotel ID as obtained from `ctrip hotel-suggest` (e.g. 375539). undefined, null, or blank/whitespace-only input raises ArgumentError 'hotel id is required ...'. It fails fast before building the hotel detail URL.
Source
Thrown at clis/ctrip/utils.js:603
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'); }, 10000);
})
`;
/* ------------------------- hotel detail (browser SSR) ------------------------- */
/** Validate a numeric Ctrip hotel id (returned by `ctrip hotel-suggest`). */
export function parseHotelId(raw) {
if (raw === undefined || raw === null || String(raw).trim() === '') {
throw new ArgumentError('hotel id is required (numeric id from `ctrip hotel-suggest`, e.g. 375539)');
}
try {
return parseStrictPositiveInteger('id', raw);
} catch {
throw new ArgumentError(`hotel id must be a positive integer, got ${JSON.stringify(raw)}`);
}
}
export function buildHotelDetailUrl(hotelId) {
return `https://hotels.ctrip.com/hotels/detail/?hotelid=${hotelId}`;
}
/**
* Browser-context IIFE that projects the single-hotel profile from
* `__NEXT_DATA__.props.pageProps.hotelDetailResponse`. Rating sub-scores, hot
* facilities, and the check-in/out policy are each joined into one string so the
* profile stays a single flat row. Returns `null` when the SSR block is absent,
* so the caller raises a typed error instead of surfacing blanks. Room-levelView on GitHub (pinned to 49907e53dc)
Solutions
- Run `ctrip hotel-suggest <name>` and pass the returned numeric hotel id (e.g. 375539).
- Ensure the id value is set and non-blank (check shell variable expansion).
- Do not pass hotel names; resolve them to numeric IDs via hotel-suggest first.
Example fix
// before ctrip hotel-detail --id "" // after ctrip hotel-detail --id 375539
Defensive patterns
Strategy: validation
Validate before calling
if (hotelId === undefined || hotelId === null || String(hotelId).trim() === '') {
throw new Error('hotel id is required: run `ctrip hotel-suggest` to get a numeric id');
} Type guard
const isPresent = (v) => v !== undefined && v !== null && String(v).trim() !== '';
Try / catch
try {
const id = parseHotelId(raw);
} catch (e) {
if (e instanceof ArgumentError && e.message.includes('hotel id is required')) {
console.error('Usage: ctrip hotel-detail --id 375539');
} else throw e;
} Prevention
- Resolve hotel names to numeric IDs via `ctrip hotel-suggest` before calling detail commands.
- Check shell variables are non-empty before flag interpolation.
- Never pass hotel names where numeric IDs are expected.
When it happens
Trigger: Running a ctrip hotel-detail command without the hotel id argument/flag, or passing an empty string or whitespace-only value.
Common situations: Skipping the `ctrip hotel-suggest` lookup step, unset shell variables expanding to empty, or passing a hotel NAME ('Grand Hyatt') instead of the numeric ID.
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
- symbol is required
- Either --product-id or --url is required
- --city is required (numeric city ID from `ctrip search` or `
- --${name} is required (e.g. 北京 / 上海)
- must be a conversation id, /app/<id> URL, or sidebar title
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/99923a4e29aaefdb.
Report an issue: GitHub.