{"record":{"id":"de06d87555075e20","repo":"jackwener/OpenCLI","slug":"name-is-required-3-letter-iata-code-e-g-lo","errorCode":null,"errorMessage":"--${name} is required (3-letter IATA code, e.g. LON, NYC)","messagePattern":"--(.+?) is required \\(3-letter IATA code, e\\.g\\. LON, NYC\\)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/trip/utils.js","lineNumber":19,"sourceCode":"/**\n * Shared helpers for the Trip.com (international) adapter.\n *\n * Trip.com is the English-facing sibling of Ctrip; its search pages render\n * results client-side, so the browser-mode commands read the rendered DOM.\n * Flight rows are `.result-item` cards keyed by stable `data-testid` anchors\n * (`flights-name`, `stopInfoText`, `flight_price_*`).\n */\nimport { ArgumentError, CommandExecutionError } from '@jackwener/opencli/errors';\n\nconst MIN_LIMIT = 1;\nconst MAX_LIMIT = 50;\nconst ISO_DATE_RE = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\nconst POI_SEARCH_ENDPOINT = 'https://www.trip.com/restapi/soa2/14427/poiSearch';\nconst PACKAGE_SEARCH_ENDPOINT = 'https://www.trip.com/restapi/soa2/19866/FlightSelectSearch';\n\nexport function parseIataCode(name, raw) {\n    if (raw === undefined || raw === null || raw === '') {\n        throw new ArgumentError(`--${name} is required (3-letter IATA code, e.g. LON, NYC)`);\n    }\n    const value = String(raw).trim().toUpperCase();\n    if (!/^[A-Z]{3}$/.test(value)) {\n        throw new ArgumentError(`--${name} must be a 3-letter IATA code, got ${JSON.stringify(raw)}`);\n    }\n    return value;\n}\n\nexport function parseIsoDate(name, raw) {\n    if (raw === undefined || raw === null || raw === '') {\n        throw new ArgumentError(`--${name} is required (YYYY-MM-DD)`);\n    }\n    const value = String(raw).trim();\n    const m = ISO_DATE_RE.exec(value);\n    if (!m) {\n        throw new ArgumentError(`--${name} must be YYYY-MM-DD, got ${JSON.stringify(raw)}`);\n    }\n    const year = Number(m[1]);","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trip/utils.js#L1-L37","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nawait tripFlightSearch({ date: '2026-09-01' }); // missing from-code\n// after\nawait tripFlightSearch({ date: '2026-09-01', fromCode: 'LON', toCode: 'NYC' });","handlingStrategy":"validation","validationCode":"function requireIata(name, value) {\n  if (value === undefined || value === null || value === '') {\n    throw new Error(`--${name} is required (3-letter IATA code)`);\n  }\n  const v = String(value).trim().toUpperCase();\n  if (!/^[A-Z]{3}$/.test(v)) throw new Error(`--${name} must be a 3-letter IATA code, got ${value}`);\n  return v;\n}\n// call before invoking the command\nrequireIata('airport', process.env.TRIP_AIRPORT);","typeGuard":"function isIataCode(v) {\n  return typeof v === 'string' && /^[A-Za-z]{3}$/.test(v);\n}","tryCatchPattern":"try {\n  const rows = await tripTransferSearch(kwargs);\n} catch (e) {\n  if (e instanceof ArgumentError && e.message.includes('is required')) {\n    console.error(e.message);\n    process.exit(1); // usage error, not retryable\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["argument-error","validation","cli","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}