jackwener/OpenCLI · error · ArgumentError
--${name} is required (YYYY-MM-DD)
Error message
--${name} is required (YYYY-MM-DD) What it means
parseIsoDate requires a date argument in YYYY-MM-DD format; this error is thrown when the argument is missing entirely (undefined, null, or empty string after conversion). It exists so CLI commands fail fast with a message naming the exact flag and expected format.
Source
Thrown at clis/trip/utils.js:30
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]);
const month = Number(m[2]);
const day = Number(m[3]);
if (month < 1 || month > 12 || day < 1 || day > 31) {
throw new ArgumentError(`--${name} has invalid month/day: ${value}`);
}
// Cross-check via UTC date math so 2026-02-30 doesn't pass.
const parsed = new Date(Date.UTC(year, month - 1, day));
if (parsed.getUTCFullYear() !== year || parsed.getUTCMonth() !== month - 1 || parsed.getUTCDate() !== day) {
throw new ArgumentError(`--${name} is not a real calendar date: ${value}`);
}
return value;View on GitHub (pinned to 49907e53dc)
Solutions
- Supply the flag with a YYYY-MM-DD value, e.g. --depart 2026-10-01
- Check the command's help output to see which date flags are required
- If the value comes from a variable/config, verify it is set and non-empty before invoking
- Default the value in a wrapper script, e.g. DEPART=$(date -d '+7 days' +%F)
Example fix
// before clis-trip hotels --city-id 338 --checkout 2026-10-05 // after clis-trip hotels --city-id 338 --checkin 2026-10-01 --checkout 2026-10-05
Defensive patterns
Strategy: validation
Validate before calling
if (depart === undefined || depart === null || String(depart).trim() === '') {
throw new Error('--depart is required (YYYY-MM-DD)');
} Type guard
function isProvided(v) {
return v !== undefined && v !== null && String(v).trim() !== '';
} Try / catch
try {
runTripCli(['flights', '--depart', depart]);
} catch (err) {
if (err instanceof ArgumentError && /is required \(YYYY-MM-DD\)/.test(err.message)) {
console.error(`Missing date flag: ${err.message}`);
process.exitCode = 2;
} else throw err;
} Prevention
- List all required flags in your wrapper scripts and assert them before invocation
- Default optional dates explicitly (e.g. tomorrow's date) instead of leaving them unset
- Check config/env sources for empty values before interpolation
- Use ${VAR:?msg} in bash to fail early on unset variables
When it happens
Trigger: Calling depart, ret, date, checkin, or checkout (which delegate to parseIsoDate) without the flag at all, or with --date '' / an unset variable that evaluates to empty.
Common situations: User forgot the flag; an env var or config value backing the argument is unset; a script interpolates an empty variable into the command line; whitespace-only value in a config file.
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
- keyword must not be empty
- <from> station must not be empty
- <to> station must not be empty
- who 不能为空
- key is required
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/6d4bdf143f2479a3.
Report an issue: GitHub.