jackwener/OpenCLI · error · ArgumentError
--${name} must be a numeric Trip.com hotel id, got ${JSON.st
Error message
--${name} must be a numeric Trip.com hotel id, got ${JSON.stringify(raw)} What it means
parseHotelId validates that a CLI option (e.g. --hotel) is a numeric Trip.com hotel id before building hotel detail URLs. When the supplied value contains anything other than digits after trimming (letters, punctuation, floats, negatives, whitespace inside), the function throws ArgumentError with the offending raw value JSON-stringified. Hotel ids on Trip.com are purely numeric strings, so any non-numeric input cannot resolve to a hotel.
Source
Thrown at clis/trip/utils.js:323
};
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
* single flat row. Returns `null` when the SSR block is absent, so the caller
* raises a typed error instead of surfacing blanks. Room-level nightly prices
* load via a post-SSR XHR and are out of scope here.
*/View on GitHub (pinned to 49907e53dc)
Solutions
- Find the numeric id via the hotels list command (discover endpoint) and pass only the digits, e.g. --hotel 1234567
- Strip any non-numeric wrapping (URL, quotes, currency symbols) before passing the value: extract with a regex like /\d+/ from a pasted URL
- Check shell quoting/escaping so no stray characters are appended to the option value
- Validate the value with /^\d+$/ in your wrapper script before invoking the CLI
Example fix
// before tripcli hotel-detail --hotel 'https://www.trip.com/hotels/detail/?hotelId=1234567' // after tripcli hotel-detail --hotel 1234567
Defensive patterns
Strategy: validation
Validate before calling
function isValidHotelId(v) { return typeof v === 'string' || typeof v === 'number' ? /^\d+$/.test(String(v).trim()) : false; }
if (!isValidHotelId(hotelId)) throw new Error(`hotel id must be numeric, got ${JSON.stringify(hotelId)}`); Type guard
const isHotelId = (v) => (typeof v === 'string' || typeof v === 'number') && /^\d+$/.test(String(v).trim());
Try / catch
try {
await runCli(['hotel-detail', '--hotel', hotelId]);
} catch (e) {
if (/must be a numeric Trip.com hotel id/.test(e.message)) {
const digits = String(hotelId).match(/\d+/);
if (digits) return runCli(['hotel-detail', '--hotel', digits[0]]);
}
throw e;
} Prevention
- Always source hotel ids from the hotels list command, not from pasted URLs
- Normalize inputs: extract digits with /\d+/ before passing
- Add a pre-call regex check (/^\d+$/) in wrapper scripts
- Avoid float/number formatting of ids from JSON — keep them as strings
When it happens
Trigger: Calling any command whose CLI handler invokes hotelId/parseHotelId with a value like 'abc123', '12345.0', '-99', '12 34', or a URL slug such as 'Hotel/Detail?hotelId=123' passed by mistake instead of the bare id.
Common situations: Developers paste the full Trip.com hotel URL or slug instead of just the id; a config/env var holds a formatted or quoted value; shell quoting injects stray characters; automation scripts pass float-formatted ids from JSON sources.
Related errors
- <train-no> "${trainNo}" does not look like a 12306 internal
- --seat-types must contain only 12306 seat letters/digits (A-
- coords must be in "x,y" format (e.g. "1,2")
- semanticscholar paper id "${value}" is not recognised
- --from station must not be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/c5e34072aecc2222.
Report an issue: GitHub.