{"record":{"id":"a4edaf3ff9d86e9c","repo":"jackwener/OpenCLI","slug":"name-is-required-numeric-trip-com-hotel-id","errorCode":null,"errorMessage":"--${name} is required (numeric Trip.com hotel id, discover via the hotels list)","messagePattern":"--(.+?) is required \\(numeric Trip\\.com hotel id, discover via the hotels list\\)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/trip/utils.js","lineNumber":319,"sourceCode":"    const detect = () => {\n      if (/captcha|verify you are human|security check/i.test(document.body?.innerText || '')) return 'captcha';\n      if (document.querySelector('.hotel-card')) return 'content';\n      return null;\n    };\n    const found = detect();\n    if (found) return resolve(found);\n    const observer = new MutationObserver(() => {\n      const result = detect();\n      if (result) { observer.disconnect(); resolve(result); }\n    });\n    observer.observe(document.documentElement, { childList: true, subtree: true });\n    setTimeout(() => { observer.disconnect(); resolve('timeout'); }, 12000);\n  })\n`;\n\nexport function parseHotelId(name, raw) {\n    if (raw === undefined || raw === null || String(raw).trim() === '') {\n        throw new ArgumentError(`--${name} is required (numeric Trip.com hotel id, discover via the hotels list)`);\n    }\n    const value = String(raw).trim();\n    if (!/^\\d+$/.test(value)) {\n        throw new ArgumentError(`--${name} must be a numeric Trip.com hotel id, got ${JSON.stringify(raw)}`);\n    }\n    return value;\n}\n\nexport function buildHotelDetailUrl(hotelId) {\n    const params = new URLSearchParams({ hotelId, locale: 'en_US', curr: 'USD' });\n    return `https://www.trip.com/hotels/detail/?${params.toString()}`;\n}\n\n/**\n * Browser-context IIFE that projects the single-hotel profile from\n * `__NEXT_DATA__.props.pageProps.hotelDetailResponse` (the same SSR shape the\n * mainland `ctrip hotel` detail uses). Rating sub-scores, popular amenities, and\n * the check-in/out policy are each joined into one string so the profile stays a","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trip/utils.js#L301-L337","documentation":"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.","triggerScenarios":"Calling hotelId (which delegates to parseHotelId) without the flag, with --hotel-id '', or with an unset variable that yields an empty string.","commonSituations":"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.","solutions":["Supply the numeric hotel id, e.g. --hotel-id 12345678","Run the hotels list command first (with a valid --city-id and dates) to discover hotel ids","Ensure the variable holding the id from the list step is actually set before invoking","Do not pass a hotel name — the id must be numeric"],"exampleFix":"// before\nclis-trip hotel-detail --hotel-id\n// after\nclis-trip hotels --city-id 338 --checkin 2026-10-01 --checkout 2026-10-05\nclis-trip hotel-detail --hotel-id 12345678","handlingStrategy":"validation","validationCode":"if (hotelId === undefined || hotelId === null || String(hotelId).trim() === '') {\n  throw new Error('--hotel-id is required (numeric Trip.com hotel id, discover via the hotels list)');\n}","typeGuard":"function isProvided(v) {\n  return v !== undefined && v !== null && String(v).trim() !== '';\n}","tryCatchPattern":"try {\n  runTripCli(['hotel-detail', '--hotel-id', hotelId]);\n} catch (err) {\n  if (err instanceof ArgumentError && /--hotel-id is required/.test(err.message)) {\n    console.error('Run the hotels list first to get a numeric hotel id, then pass --hotel-id <digits>.');\n    process.exitCode = 2;\n  } else throw err;\n}","preventionTips":["Chain the hotels-list command to capture an id before hotel-detail calls","Assert the id variable is non-empty in wrapper scripts","Store discovered ids in a cache keyed by city and dates","Never pass hotel names where a numeric id is expected"],"tags":["cli","missing-argument","trip-com"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}