jackwener/OpenCLI · error · ArgumentError

--from and --to must differ (got ${fromCode})

Error message

--from and --to must differ (got ${fromCode})

What it means

This ArgumentError is thrown before any network call in clis/trip/flight.js when parseIataCode resolves --from and --to to the same IATA code. Trip.com one-way flight search is meaningless for identical origin and destination, so the command fails fast with the resolved code included in the message. It is an input validation error, not a runtime or site issue.

Source

Thrown at clis/trip/flight.js:48

        { name: 'from', required: true, positional: true, help: 'Departure IATA code (e.g. LON / LHR)' },
        { name: 'to', required: true, positional: true, help: 'Arrival IATA code (e.g. NYC / JFK)' },
        { name: 'date', required: true, help: 'Departure date (YYYY-MM-DD)' },
        { name: 'limit', type: 'int', default: 20, help: 'Number of flights (1-50)' },
    ],
    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 date = parseIsoDate('date', kwargs.date);
        const limit = parseListLimit(kwargs.limit);

        const searchUrl = buildFlightSearchUrl(fromCode, toCode, date);
        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

  1. Check the command invocation and supply two different IATA codes for --from and --to.
  2. Validate in a wrapper script that from !== to (after normalization to uppercase) before invoking the command.
  3. If an airport pair is dynamically generated, guard against degenerate from==to pairs at generation time.

Example fix

// before
await runTripFlight({ from: args.from, to: args.to }); // both 'SFO'
// after
const from = args.from.trim().toUpperCase();
const to = args.to.trim().toUpperCase();
if (from === to) throw new Error('--from and --to must differ');
await runTripFlight({ from, to });
Defensive patterns

Strategy: validation

Validate before calling

const norm = (s) => String(s || '').trim().toUpperCase();
const from = norm(kwargs.from), to = norm(kwargs.to);
if (!/^[A-Z]{3}$/.test(from) || !/^[A-Z]{3}$/.test(to)) throw new Error('from/to must be 3-letter IATA codes');
if (from === to) throw new Error(`--from and --to must differ (got ${from})`);

Type guard

null

Try / catch

try {
  await runTripFlight(args);
} catch (e) {
  if (e instanceof ArgumentError) {
    console.error(`Bad arguments: ${e.message}`);
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Invoking the one-way flight command with --from and --set --to that normalize to the same IATA code, e.g. --from sfo --to SFO, or two aliases (city name and code) that resolve to the same airport.

Common situations: Copy-pasting the same code into both flags; case/format differences masking the equality ('sfo' vs 'SFO'); scripting that interpolates the same variable into both flags; users misunderstanding that origin and destination must be distinct airports.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/5024934745792330. Report an issue: GitHub.