{"record":{"id":"ffdf6c813b028226","repo":"jackwener/OpenCLI","slug":"depart-must-be-before-return-got-depart-ffdf6c","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/package.js","lineNumber":56,"sourceCode":"        { name: 'return', required: true, help: 'Return date (YYYY-MM-DD)' },\n        { name: 'adults', type: 'int', default: 2, help: 'Number of adults (1-9, default 2)' },\n        { name: 'limit', type: 'int', default: 20, help: 'Number of packages (1-50)' },\n    ],\n    columns: [\n        'rank',\n        'airline', 'flightNo',\n        'from', 'to',\n        'departure', 'arrival',\n        'stops',\n        'price', 'currency',\n    ],\n    func: async (kwargs) => {\n        const from = parseKeyword('from', kwargs.from);\n        const to = parseKeyword('to', kwargs.to);\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 adults = parseAdults(kwargs.adults);\n        const limit = parseListLimit(kwargs.limit);\n\n        const origin = await resolvePackageCity(from);\n        if (!origin) {\n            throw new ArgumentError(`Could not resolve origin \"${from}\" to a Trip.com city; run 'trip search ${from}' to find the name`);\n        }\n        const dest = await resolvePackageCity(to);\n        if (!dest) {\n            throw new ArgumentError(`Could not resolve destination \"${to}\" to a Trip.com city; run 'trip search ${to}' to find the name`);\n        }\n        if (origin.cityId === dest.cityId) {\n            throw new ArgumentError(`--from and --to must differ (both resolved to ${dest.name})`);\n        }\n\n        const groups = await fetchPackageSearch({\n            dcode: origin.cityCode,","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trip/package.js#L38-L74","documentation":"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.","triggerScenarios":"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.","commonSituations":"Swapped argument order in scripts, off-by-one date arithmetic producing ret == depart, or assuming single-day packages are allowed.","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"],"exampleFix":"// before\n['--depart', d, '--return', d] // equal dates\n// after\nconst ret = addDays(d, 1);\n['--depart', d, '--return', ret]","handlingStrategy":"validation","validationCode":"const depart = parseIsoDate('depart', kwargs.depart);\nconst ret = parseIsoDate('return', kwargs.return);\nif (!(depart < ret)) {\n  throw new Error(`--depart must be before --return (got ${depart} .. ${ret})`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await tripPackageSearch({ depart, return: ret });\n} catch (e) {\n  if (e instanceof ArgumentError && e.message.includes('--depart must be before')) {\n    throw new UserInputError('Departure date must precede the return date');\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["validation","cli","dates","arguments"],"backgroundTag":"invalid-cli-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}