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
ArgumentError thrown when the parsed --depart date is not strictly before the parsed --return date (including equal dates and inverted ranges). A round trip requires depart < return, so the library validates this before building the search URL.
Source
Thrown at clis/trip/flight-round.js:54
columns: [
'rank',
'airline',
'departureTime', 'departureAirport',
'arrivalTime', 'arrivalAirport',
'duration', 'stops',
'price', 'currency',
'url',
],
func: async (page, kwargs) => {
const fromCode = parseIataCode('from', kwargs.from);
const toCode = parseIataCode('to', kwargs.to);
if (fromCode === toCode) {
throw new ArgumentError(`--from and --to must differ (got ${fromCode})`);
}
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 limit = parseListLimit(kwargs.limit);
const searchUrl = buildFlightRoundSearchUrl(fromCode, toCode, depart, ret);
await page.goto(searchUrl);
const waitResult = await page.evaluate(WAIT_FOR_FLIGHTS_JS);
if (waitResult === 'captcha') {
throw new AuthRequiredError('trip.com', 'Trip.com is asking for a verification; complete it in your browser session and retry');
}
if (waitResult !== 'content') {
throw new CommandExecutionError(`Trip.com flight page did not render flight cards (state=${String(waitResult)})`);
}
const raw = await page.evaluate(buildFlightExtractJs());
if (!Array.isArray(raw)) {
const reason = raw && typeof raw === 'object' && typeof raw.error === 'string'
&& /^malformed flight card \d+: [a-z /]+$/.test(raw.error)
? `: ${raw.error}`
: '';View on GitHub (pinned to 49907e53dc)
Solutions
- Ensure --return is a strictly later date than --depart (use YYYY-MM-DD ISO format)
- Check the order of variables feeding these flags in your script
- Verify date formats match the expected ISO date (parseIsoDate input)
- For same-day travel, check whether the site/command supports it or pick different dates
Example fix
// before --depart 2026-09-08 --return 2026-09-01 // after --depart 2026-09-01 --return 2026-09-08
Defensive patterns
Strategy: validation
Validate before calling
function validDateRange(depart, ret) {
const d = new Date(depart), r = new Date(ret);
return !isNaN(d.getTime()) && !isNaN(r.getTime()) && d.getTime() < r.getTime();
}
if (!validDateRange(depart, ret)) throw new Error('--depart must be an earlier ISO date than --return'); Type guard
function isOrderedDatePair(a, b): boolean {
return Date.parse(a) < Date.parse(b);
} Try / catch
try {
await runFlightRound({ from, to, depart, ret });
} catch (e) {
if (e instanceof ArgumentError && /--depart must be before --return/.test(e.message)) {
console.error(`Bad date range: ${e.message}. Use YYYY-MM-DD with return > depart.`);
} else { throw e; }
} Prevention
- Always pass dates as explicit YYYY-MM-DD ISO strings
- Order-check dates in the caller before invoking the command
- Watch for locale date-format confusion (DD/MM vs MM/DD) in inputs
When it happens
Trigger: Calling flight-round with --depart equal to --return (same-day), or with the dates swapped so depart > return, e.g. --depart 2026-09-08 --return 2026-09-01.
Common situations: DD/MM vs MM/DD confusion producing an inverted range; passing ISO strings in the wrong order via variables; users wanting same-day trips unsupported by this command; timezone-insensitive date parsing surprises.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- --from and --to must differ (got ${fromCode})
- --from and --to must differ (got ${fromCode})
- --checkin must be before --checkout (got ${checkin} .. ${che
- 1688 item expects an offer URL or offer ID
- Invalid 1688 URL
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/be5e784eede8996a.
Report an issue: GitHub.