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
- Ensure --return is at least one day after --depart
- Check argument ordering in scripts that compute the dates programmatically
- Catch ArgumentError and surface a clear message to the end user
- 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
- Compute the return date as at least depart + 1 day
- Double-check argument order when dates come from variables
- Add a date-order check to any script that generates these flags
- Remember same-day (depart == return) package searches are rejected
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
- ${label} is required
- ${label} must be a positive integer
- ${label} must be <= ${maxValue}
- dblp ${label} must be a positive integer
- dblp ${label} must be <= ${maxValue}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/ffdf6c813b028226.
Report an issue: GitHub.