jackwener/OpenCLI · error · ArgumentError
--${name} must be YYYY-MM-DD, got ${JSON.stringify(raw)}
Error message
--${name} must be YYYY-MM-DD, got ${JSON.stringify(raw)} What it means
parseIsoDate rejects a provided date value that does not match the strict YYYY-MM-DD pattern (ISO_DATE_RE). The value must be digits in the exact form year-month-day; other formats or stray characters are rejected. This keeps downstream URL building and date math working on a canonical format.
Source
Thrown at clis/trip/utils.js:35
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;
}
export function parseListLimit(raw, fallback = 20) {
if (raw === undefined || raw === null || raw === '') return fallback;
const parsed = Number(raw);View on GitHub (pinned to 49907e53dc)
Solutions
- Reformat the value to strict YYYY-MM-DD, e.g. 2026-10-01
- Zero-pad month and day to two digits (2026-1-5 -> 2026-01-05)
- Strip time components if passing a Date/ISO timestamp: slice(0,10) or toISOString().slice(0,10)
- Avoid locale-dependent formatting; use explicit yyyy-MM-dd formatting
Example fix
// before clis-trip flights --from LON --to NYC --depart 10/01/2026 // after clis-trip flights --from LON --to NYC --depart 2026-10-01
Defensive patterns
Strategy: validation
Validate before calling
const ISO_DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
if (!ISO_DATE_RE.test(String(depart).trim())) {
throw new Error(`--depart must be YYYY-MM-DD, got ${JSON.stringify(depart)}`);
} Type guard
function isIsoDateString(v) {
return typeof v === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(v.trim());
} Try / catch
try {
runTripCli(['flights', '--depart', depart]);
} catch (err) {
if (err instanceof ArgumentError && /must be YYYY-MM-DD/.test(err.message)) {
console.error(`Reformat date as YYYY-MM-DD: ${err.message}`);
process.exitCode = 2;
} else throw err;
} Prevention
- Always generate dates with toISOString().slice(0,10) or explicit yyyy-MM-dd formatting
- Never pass locale-formatted or Date.toString() output directly
- Zero-pad month and day to two digits
- Normalize all dates at your system boundary before they reach the CLI
When it happens
Trigger: Passing dates like '01/10/2026', '2026-1-5', '2026/10/01', 'Oct 5 2026', '2026-10-01T00:00', or a full timestamp string to depart/ret/date/checkin/checkout.
Common situations: US-style MM/DD/YYYY habits; locale-formatted dates pasted from a calendar app; Date objects stringified with time components; spreadsheets exporting dates with slashes.
Related errors
- ${label} is required (YYYY-MM-DD)
- --${name} must be YYYY-MM-DD, got ${JSON.stringify(raw)}
- --${name} has invalid month/day: ${value}
- huodongxing ${label} must be a valid YYYY-MM-DD date
- Date must be YYYY-MM-DD: ${date}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/7ff7c536b19d03b3.
Report an issue: GitHub.