{"record":{"id":"0df615d7fc183eff","repo":"jackwener/OpenCLI","slug":"adults-must-be-an-integer-between-1-and-9-got","errorCode":null,"errorMessage":"--adults must be an integer between 1 and 9, got ${JSON.stringify(raw)}","messagePattern":"--adults must be an integer between 1 and 9, got (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/trip/package.js","lineNumber":21,"sourceCode":" *\n * Trip.com prices its packages through the flight-selection step of the booking\n * flow: a public, unsigned POST keyed on the metro city codes plus the\n * destination hotel city id returns the outbound flight options priced at the\n * bundle rate (the specific hotel is picked in a later step). So this is a plain\n * public fetch (no browser) that resolves both endpoints through the same POI\n * search `trip search` uses, then lists the package flights (see\n * `fetchPackageSearch` in utils). Per-person package fares only; the return leg\n * rides on the hotel checkout date.\n */\nimport { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nimport { fetchPackageSearch, mapPackageRow, parseIsoDate, parseKeyword, parseListLimit, resolvePackageCity } from './utils.js';\n\nfunction parseAdults(raw) {\n    if (raw === undefined || raw === null || raw === '') return 2;\n    const parsed = Number(raw);\n    if (!Number.isInteger(parsed) || parsed < 1 || parsed > 9) {\n        throw new ArgumentError(`--adults must be an integer between 1 and 9, got ${JSON.stringify(raw)}`);\n    }\n    return parsed;\n}\n\ncli({\n    site: 'trip',\n    name: 'package',\n    access: 'read',\n    description: 'Search Trip.com flight+hotel packages by route + dates; lists the package flight options priced at the bundle rate',\n    domain: 'trip.com',\n    strategy: Strategy.PUBLIC,\n    browser: false,\n    args: [\n        { name: 'from', required: true, positional: true, help: 'Origin city keyword (e.g. Seoul / London / Bangkok)' },\n        { name: 'to', required: true, positional: true, help: 'Destination city keyword (e.g. Tokyo / Paris / Singapore)' },\n        { name: 'depart', required: true, help: 'Outbound date (YYYY-MM-DD)' },\n        { name: 'return', required: true, help: 'Return date (YYYY-MM-DD)' },\n        { name: 'adults', type: 'int', default: 2, help: 'Number of adults (1-9, default 2)' },","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trip/package.js#L3-L39","documentation":"parseAdults validates the --adults option: undefined/null/'' default to 2, otherwise the value must be an integer from 1 to 9. Any other input — non-numeric strings, floats, or out-of-range numbers — throws this ArgumentError before any network call is made.","triggerScenarios":"Passing --adults with a non-integer (e.g. 'two', 2.5), a value below 1 (0, -1), or above 9 (10+), including JSON-encoded or whitespace-padded strings that Number() parses to a non-integer or out-of-range value.","commonSituations":"Scripting the CLI with unvalidated user input, passing '--adults \"\"' expecting 1 instead of the default 2, or confusing the 9-guest cap with a larger group size.","solutions":["Pass an integer between 1 and 9 for --adults","Omit --adults entirely to use the default of 2","Validate/parse the value in your wrapper script before invoking the CLI","Split groups larger than 9 into multiple package searches"],"exampleFix":"// before\nspawn('trip', ['package', '--adults', '12'])\n// after\nspawn('trip', ['package', '--adults', '9']) // or split into two searches of <=9","handlingStrategy":"validation","validationCode":"const n = raw === undefined || raw === null || raw === '' ? 2 : Number(raw);\nif (!Number.isInteger(n) || n < 1 || n > 9) {\n  throw new Error(`--adults must be an integer between 1 and 9, got ${JSON.stringify(raw)}`);\n}","typeGuard":"function isValidAdults(v) {\n  return v === undefined || v === null || v === '' ||\n    (Number.isInteger(Number(v)) && Number(v) >= 1 && Number(v) <= 9);\n}","tryCatchPattern":"try {\n  await tripPackageSearch({ adults: raw });\n} catch (e) {\n  if (e instanceof ArgumentError && e.message.includes('--adults')) {\n    return tripPackageSearch({}); // fall back to default adults=2\n  }\n  throw e;\n}","preventionTips":["Validate the adults count in wrappers before invoking the CLI","Remember the default is 2 when --adults is omitted or empty","Split parties larger than 9 into multiple searches","Never pass free-text user input directly as --adults"],"tags":["validation","cli","arguments","input-validation"],"backgroundTag":"invalid-cli-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}