{"record":{"id":"be5e784eede8996a","repo":"jackwener/OpenCLI","slug":"depart-must-be-before-return-got-depart","errorCode":null,"errorMessage":"--depart must be before --return (got ${depart} .. ${ret})","messagePattern":"--depart must be before --return \\(got (.+?) \\.\\. (.+?)\\)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/trip/flight-round.js","lineNumber":54,"sourceCode":"    columns: [\n        'rank',\n        'airline',\n        'departureTime', 'departureAirport',\n        'arrivalTime', 'arrivalAirport',\n        'duration', 'stops',\n        'price', 'currency',\n        'url',\n    ],\n    func: async (page, kwargs) => {\n        const fromCode = parseIataCode('from', kwargs.from);\n        const toCode = parseIataCode('to', kwargs.to);\n        if (fromCode === toCode) {\n            throw new ArgumentError(`--from and --to must differ (got ${fromCode})`);\n        }\n        const depart = parseIsoDate('depart', kwargs.depart);\n        const ret = parseIsoDate('return', kwargs.return);\n        if (depart >= ret) {\n            throw new ArgumentError(`--depart must be before --return (got ${depart} .. ${ret})`);\n        }\n        const limit = parseListLimit(kwargs.limit);\n\n        const searchUrl = buildFlightRoundSearchUrl(fromCode, toCode, depart, ret);\n        await page.goto(searchUrl);\n        const waitResult = await page.evaluate(WAIT_FOR_FLIGHTS_JS);\n        if (waitResult === 'captcha') {\n            throw new AuthRequiredError('trip.com', 'Trip.com is asking for a verification; complete it in your browser session and retry');\n        }\n        if (waitResult !== 'content') {\n            throw new CommandExecutionError(`Trip.com flight page did not render flight cards (state=${String(waitResult)})`);\n        }\n        const raw = await page.evaluate(buildFlightExtractJs());\n        if (!Array.isArray(raw)) {\n            const reason = raw && typeof raw === 'object' && typeof raw.error === 'string'\n                && /^malformed flight card \\d+: [a-z /]+$/.test(raw.error)\n                ? `: ${raw.error}`\n                : '';","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trip/flight-round.js#L36-L72","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n--depart 2026-09-08 --return 2026-09-01\n// after\n--depart 2026-09-01 --return 2026-09-08","handlingStrategy":"validation","validationCode":"function validDateRange(depart, ret) {\n    const d = new Date(depart), r = new Date(ret);\n    return !isNaN(d.getTime()) && !isNaN(r.getTime()) && d.getTime() < r.getTime();\n}\nif (!validDateRange(depart, ret)) throw new Error('--depart must be an earlier ISO date than --return');","typeGuard":"function isOrderedDatePair(a, b): boolean {\n    return Date.parse(a) < Date.parse(b);\n}","tryCatchPattern":"try {\n    await runFlightRound({ from, to, depart, ret });\n} catch (e) {\n    if (e instanceof ArgumentError && /--depart must be before --return/.test(e.message)) {\n        console.error(`Bad date range: ${e.message}. Use YYYY-MM-DD with return > depart.`);\n    } else { throw e; }\n}","preventionTips":["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"],"tags":["argument-validation","date-validation","input-error","trip-com"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}