jackwener/OpenCLI · error · ArgumentError
--adults must be an integer between 1 and 9, got ${JSON.stri
Error message
--adults must be an integer between 1 and 9, got ${JSON.stringify(raw)} What it means
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.
Source
Thrown at clis/trip/package.js:21
*
* Trip.com prices its packages through the flight-selection step of the booking
* flow: a public, unsigned POST keyed on the metro city codes plus the
* destination hotel city id returns the outbound flight options priced at the
* bundle rate (the specific hotel is picked in a later step). So this is a plain
* public fetch (no browser) that resolves both endpoints through the same POI
* search `trip search` uses, then lists the package flights (see
* `fetchPackageSearch` in utils). Per-person package fares only; the return leg
* rides on the hotel checkout date.
*/
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';
import { fetchPackageSearch, mapPackageRow, parseIsoDate, parseKeyword, parseListLimit, resolvePackageCity } from './utils.js';
function parseAdults(raw) {
if (raw === undefined || raw === null || raw === '') return 2;
const parsed = Number(raw);
if (!Number.isInteger(parsed) || parsed < 1 || parsed > 9) {
throw new ArgumentError(`--adults must be an integer between 1 and 9, got ${JSON.stringify(raw)}`);
}
return parsed;
}
cli({
site: 'trip',
name: 'package',
access: 'read',
description: 'Search Trip.com flight+hotel packages by route + dates; lists the package flight options priced at the bundle rate',
domain: 'trip.com',
strategy: Strategy.PUBLIC,
browser: false,
args: [
{ name: 'from', required: true, positional: true, help: 'Origin city keyword (e.g. Seoul / London / Bangkok)' },
{ name: 'to', required: true, positional: true, help: 'Destination city keyword (e.g. Tokyo / Paris / Singapore)' },
{ name: 'depart', required: true, help: 'Outbound date (YYYY-MM-DD)' },
{ name: 'return', required: true, help: 'Return date (YYYY-MM-DD)' },
{ name: 'adults', type: 'int', default: 2, help: 'Number of adults (1-9, default 2)' },View on GitHub (pinned to 49907e53dc)
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
Example fix
// before
spawn('trip', ['package', '--adults', '12'])
// after
spawn('trip', ['package', '--adults', '9']) // or split into two searches of <=9 Defensive patterns
Strategy: validation
Validate before calling
const n = raw === undefined || raw === null || raw === '' ? 2 : Number(raw);
if (!Number.isInteger(n) || n < 1 || n > 9) {
throw new Error(`--adults must be an integer between 1 and 9, got ${JSON.stringify(raw)}`);
} Type guard
function isValidAdults(v) {
return v === undefined || v === null || v === '' ||
(Number.isInteger(Number(v)) && Number(v) >= 1 && Number(v) <= 9);
} Try / catch
try {
await tripPackageSearch({ adults: raw });
} catch (e) {
if (e instanceof ArgumentError && e.message.includes('--adults')) {
return tripPackageSearch({}); // fall back to default adults=2
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.
Related errors
- tvmaze ${label} must be a positive integer
- ${label} is required
- ${label} must be a positive integer
- ${label} must be <= ${maxValue}
- coingecko derivatives limit must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/0df615d7fc183eff.
Report an issue: GitHub.