jackwener/OpenCLI · error · ArgumentError
--return (${ret}) must be on or after --depart (${depart})
Error message
--return (${ret}) must be on or after --depart (${depart}) What it means
An ArgumentError raised when the parsed --return date is earlier than the parsed --depart date. Both dates go through parseIsoDate first, so this compares normalized ISO strings (YYYY-MM-DD lexicographic comparison is chronologically correct). A round-trip search cannot return before it departs.
Source
Thrown at clis/ctrip/flight-round.js:74
],
columns: [
'rank',
'airline', 'flightNo', 'aircraft',
'departureTime', 'departureAirport',
'arrivalTime', 'arrivalAirport', 'terminal',
'price', 'currency', 'cabin',
'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 (ret < depart) {
throw new ArgumentError(`--return (${ret}) must be on or after --depart (${depart})`);
}
const limit = parseListLimit(kwargs.limit);
const searchUrl =
`https://flights.ctrip.com/online/list/round-${fromCode.toLowerCase()}-${toCode.toLowerCase()}` +
`?depdate=${depart}_${ret}&cabin=Y_S_C_F&adult=1&child=0&infant=0`;
await page.goto(searchUrl);
const waitResult = await page.evaluate(WAIT_FOR_FLIGHTS_ROUND_JS);
if (waitResult === 'captcha') {
throw new AuthRequiredError('flights.ctrip.com', 'Ctrip is asking for a captcha; complete it in your browser session and retry');
}
if (waitResult !== 'content') {
throw new CommandExecutionError(`Ctrip round-trip flight page did not render flight cards (state=${String(waitResult)})`);
}
const renderedCardCount = await page.evaluate(buildScrollUntilJs(ROUND_CARD_SELECTOR, limit));
const raw = await page.evaluate(buildFlightExtractJs(ROUND_CARD_SELECTOR, false));
if (!Array.isArray(raw)) {
throw new CommandExecutionError('Ctrip round-trip flight DOM extraction returned malformed rows');View on GitHub (pinned to 49907e53dc)
Solutions
- Swap or correct the dates so --return is on or after --depart.
- Validate the pair in your calling code before invoking the CLI.
- If the return date is computed, check the timezone/arithmetic that produced it.
- Note the error message includes both dates — verify which one is wrong against the logged values.
Example fix
// before cli(['flight-round', '--depart', ret, '--return', dep]); // after cli(['flight-round', '--depart', dep, '--return', ret]); // ret >= dep validated before call
Defensive patterns
Strategy: validation
Validate before calling
function validateRoundTrip(depart, ret) {
const iso = /^\d{4}-\d{2}-\d{2}$/;
if (!iso.test(depart) || !iso.test(ret)) throw new Error('dates must be YYYY-MM-DD');
if (ret < depart) throw new Error(`--return (${ret}) must be on or after --depart (${depart})`);
} Type guard
function isOnOrAfter(ret, depart) { return /^\d{4}-\d{2}-\d{2}$/.test(ret) && /^\d{4}-\d{2}-\d{2}$/.test(depart) && ret >= depart; } Try / catch
try { await cli(['flight-round','--depart',dep,'--return',ret]); } catch (e) { if (e instanceof ArgumentError && e.message.includes('--return')) { logDateValidationError(dep, ret); } else throw e; } Prevention
- Validate depart <= return in the caller before invoking the CLI.
- Be careful with timezones when computing dates; format to YYYY-MM-DD explicitly.
- Check argument order when building CLI invocations programmatically.
- Reuse one date-normalization helper for both flags.
When it happens
Trigger: Calling flight-round with a return date strictly before the depart date, e.g. `--depart 2026-03-10 --return 2026-03-05`.
Common situations: Mixing up argument order in scripts or positional args; computing the return date from the wrong base variable; timezone bugs that shift a computed return date a day backward; user input where the user thinks of depart/return reversed.
Related errors
- --from and --to must differ (got ${fromCity})
- --from and --to must differ (got ${fromCode})
- <train-no> "${trainNo}" does not look like a 12306 internal
- --from station must not be empty
- --to station must not be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/539d35adbbd3889f.
Report an issue: GitHub.