jackwener/OpenCLI · error · ArgumentError

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

Error message

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

What it means

ArgumentError thrown by input validation in the round-trip flight command: after both --from and --to are parsed as IATA codes they are equal, which would produce a meaningless search (departing and arriving at the same airport). The library rejects it up front before any network request.

Source

Thrown at clis/trip/flight-round.js:49

        { name: 'to', required: true, positional: true, help: 'Arrival IATA code (e.g. NYC / JFK)' },
        { name: 'depart', required: true, help: 'Outbound date (YYYY-MM-DD)' },
        { name: 'return', required: true, help: 'Return 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 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());

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass two different IATA codes for --from and --to
  2. Check the script/config that fills these flags for a copy-paste or variable-shadowing bug
  3. If you truly need same-airport segments, use a different command (multi-city), not flight-round

Example fix

// before
cli --trip flight-round --from PEK --to PEK --depart 2026-09-01 --return 2026-09-08
// after
cli --trip flight-round --from PEK --to SHA --depart 2026-09-01 --return 2026-09-08
Defensive patterns

Strategy: validation

Validate before calling

function validRoundTrip(from, to) {
    const f = String(from).trim().toUpperCase();
    const t = String(to).trim().toUpperCase();
    return /^[A-Z]{3}$/.test(f) && /^[A-Z]{3}$/.test(t) && f !== t;
}
if (!validRoundTrip(from, to)) throw new Error('--from and --to must be different IATA codes');

Type guard

function isDistinctIataPair(from, to): boolean {
    return typeof from === 'string' && typeof to === 'string'
        && from.trim().toUpperCase() !== to.trim().toUpperCase();
}

Try / catch

try {
    await runFlightRound({ from, to, depart, ret });
} catch (e) {
    if (e instanceof ArgumentError && /must differ/.test(e.message)) {
        console.error(`Bad route: ${e.message}. Provide two different airports.`);
    } else { throw e; }
}

Prevention

When it happens

Trigger: Invoking the Trip.com flight-round command with identical origin and destination, e.g. --from PEK --to PEK, or codes that normalize to the same airport.

Common situations: Script variable mixups where from and to are populated from the same source; typo where both flags got the same value; users expecting multi-city search but using round-trip command.

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


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