jackwener/OpenCLI · error · ArgumentError

--depart must be before --return (got ${depart} .. ${ret})

Error message

--depart must be before --return (got ${depart} .. ${ret})

What it means

This ArgumentError enforces that the parsed --depart ISO date is strictly earlier than the parsed --return date; depart >= ret is rejected. It is a pre-flight argument consistency check performed before any city resolution or network request.

Source

Thrown at clis/trip/package.js:56

        { name: 'return', required: true, help: 'Return date (YYYY-MM-DD)' },
        { name: 'adults', type: 'int', default: 2, help: 'Number of adults (1-9, default 2)' },
        { name: 'limit', type: 'int', default: 20, help: 'Number of packages (1-50)' },
    ],
    columns: [
        'rank',
        'airline', 'flightNo',
        'from', 'to',
        'departure', 'arrival',
        'stops',
        'price', 'currency',
    ],
    func: async (kwargs) => {
        const from = parseKeyword('from', kwargs.from);
        const to = parseKeyword('to', kwargs.to);
        const depart = parseIsoDate('depart', kwargs.depart);
        const ret = parseIsoDate('return', kwargs.return);
        if (depart >= ret) {
            throw new ArgumentError(`--depart must be before --return (got ${depart} .. ${ret})`);
        }
        const adults = parseAdults(kwargs.adults);
        const limit = parseListLimit(kwargs.limit);

        const origin = await resolvePackageCity(from);
        if (!origin) {
            throw new ArgumentError(`Could not resolve origin "${from}" to a Trip.com city; run 'trip search ${from}' to find the name`);
        }
        const dest = await resolvePackageCity(to);
        if (!dest) {
            throw new ArgumentError(`Could not resolve destination "${to}" to a Trip.com city; run 'trip search ${to}' to find the name`);
        }
        if (origin.cityId === dest.cityId) {
            throw new ArgumentError(`--from and --to must differ (both resolved to ${dest.name})`);
        }

        const groups = await fetchPackageSearch({
            dcode: origin.cityCode,

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Ensure --return is at least one day after --depart
  2. Check argument ordering in scripts that compute the dates programmatically
  3. Catch ArgumentError and surface a clear message to the end user
  4. If a day trip is intended, use a product that supports it — this package search requires an overnight range

Example fix

// before
['--depart', d, '--return', d] // equal dates
// after
const ret = addDays(d, 1);
['--depart', d, '--return', ret]
Defensive patterns

Strategy: validation

Validate before calling

const depart = parseIsoDate('depart', kwargs.depart);
const ret = parseIsoDate('return', kwargs.return);
if (!(depart < ret)) {
  throw new Error(`--depart must be before --return (got ${depart} .. ${ret})`);
}

Try / catch

try {
  await tripPackageSearch({ depart, return: ret });
} catch (e) {
  if (e instanceof ArgumentError && e.message.includes('--depart must be before')) {
    throw new UserInputError('Departure date must precede the return date');
  }
  throw e;
}

Prevention

When it happens

Trigger: Passing --return on or before --depart — equal dates (day trip packages unsupported), swapped values (--depart 2026-05-10 --return 2026-05-01), or same-date strings differing only in format that parse to identical values.

Common situations: Swapped argument order in scripts, off-by-one date arithmetic producing ret == depart, or assuming single-day packages are allowed.

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


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/ffdf6c813b028226. Report an issue: GitHub.