jackwener/OpenCLI · error · ArgumentError
--${name} is required (3-letter IATA code, e.g. LON, NYC)
Error message
--${name} is required (3-letter IATA code, e.g. LON, NYC) What it means
ArgumentError thrown by parseIataCode when the named CLI flag is missing, null, or an empty string. The library requires a proper 3-letter IATA airport/city code (like LON or NYC) for the given option, and refuses to run with it absent.
Source
Thrown at clis/trip/utils.js:19
/**
* Shared helpers for the Trip.com (international) adapter.
*
* Trip.com is the English-facing sibling of Ctrip; its search pages render
* results client-side, so the browser-mode commands read the rendered DOM.
* Flight rows are `.result-item` cards keyed by stable `data-testid` anchors
* (`flights-name`, `stopInfoText`, `flight_price_*`).
*/
import { ArgumentError, CommandExecutionError } from '@jackwener/opencli/errors';
const MIN_LIMIT = 1;
const MAX_LIMIT = 50;
const ISO_DATE_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
const POI_SEARCH_ENDPOINT = 'https://www.trip.com/restapi/soa2/14427/poiSearch';
const PACKAGE_SEARCH_ENDPOINT = 'https://www.trip.com/restapi/soa2/19866/FlightSelectSearch';
export function parseIataCode(name, raw) {
if (raw === undefined || raw === null || raw === '') {
throw new ArgumentError(`--${name} is required (3-letter IATA code, e.g. LON, NYC)`);
}
const value = String(raw).trim().toUpperCase();
if (!/^[A-Z]{3}$/.test(value)) {
throw new ArgumentError(`--${name} must be a 3-letter IATA code, got ${JSON.stringify(raw)}`);
}
return value;
}
export function parseIsoDate(name, raw) {
if (raw === undefined || raw === null || raw === '') {
throw new ArgumentError(`--${name} is required (YYYY-MM-DD)`);
}
const value = String(raw).trim();
const m = ISO_DATE_RE.exec(value);
if (!m) {
throw new ArgumentError(`--${name} must be YYYY-MM-DD, got ${JSON.stringify(raw)}`);
}
const year = Number(m[1]);View on GitHub (pinned to 49907e53dc)
Solutions
- Supply the missing flag with a 3-letter IATA code (e.g. --airport LHR)
- Trim/normalize the value — the function uppercases, but the input must be exactly 3 letters
- If the value may be absent, validate in your wrapper before invoking
- Check shell variables aren't expanding to empty strings
Example fix
// before
await tripFlightSearch({ date: '2026-09-01' }); // missing from-code
// after
await tripFlightSearch({ date: '2026-09-01', fromCode: 'LON', toCode: 'NYC' }); Defensive patterns
Strategy: validation
Validate before calling
function requireIata(name, value) {
if (value === undefined || value === null || value === '') {
throw new Error(`--${name} is required (3-letter IATA code)`);
}
const v = String(value).trim().toUpperCase();
if (!/^[A-Z]{3}$/.test(v)) throw new Error(`--${name} must be a 3-letter IATA code, got ${value}`);
return v;
}
// call before invoking the command
requireIata('airport', process.env.TRIP_AIRPORT); Type guard
function isIataCode(v) {
return typeof v === 'string' && /^[A-Za-z]{3}$/.test(v);
} Try / catch
try {
const rows = await tripTransferSearch(kwargs);
} catch (e) {
if (e instanceof ArgumentError && e.message.includes('is required')) {
console.error(e.message);
process.exit(1); // usage error, not retryable
}
throw e;
} Prevention
- Validate IATA flags at the top of your script before any network work
- Uppercase and trim inputs defensively
- Never pass raw airport names where a code is expected
- Check CI env vars are populated before running trip commands
When it happens
Trigger: Calling a trip command that requires --from-code/--to-code/--airport (via fromCode, toCode, or airport callers) without supplying the flag, or passing '' explicitly; also fired when a value is supplied but fails the /^[A-Z]{3}$/ check, producing the sibling message.
Common situations: Forgetting the flag in scripts/CI; passing a lowercase or 2-letter code; passing a full airport name instead of the IATA code; shell variable interpolating to empty string.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- symbol is required
- Either --product-id or --url is required
- --city is required (numeric city ID from `ctrip search` or `
- --${name} is required (e.g. 北京 / 上海)
- hotel id is required (numeric id from `ctrip hotel-suggest`,
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/de06d87555075e20.
Report an issue: GitHub.