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 throws this ArgumentError when the provided value does not match the strict YYYY-MM-DD pattern /^\d{4}-\d{2}-\d{2}$/. The raw input is JSON-stringified into the message. No coercion (e.g. 2026/09/01 or 20260901) is attempted, keeping behavior deterministic.
Source
Thrown at clis/ctrip/utils.js:215
};
}
/* --------- Helpers shared by hotel-search / flight (browser-context) ---------- */
const ISO_DATE_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
/**
* Validate YYYY-MM-DD and return the canonical string. Rejects out-of-range
* month/day, malformed input, and silent NaN. Does NOT coerce or shift timezones.
*/
export function parseIsoDate(name, raw) {
if (raw === undefined || raw === null || raw === '' || String(raw).trim() === '') {
throw new ArgumentError(`--${name} is required (YYYY-MM-DD)`);
}
const value = String(raw);
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;
}
/**
* Validate a 3-letter IATA airport / metro code, return uppercase.
* Ctrip URL accepts both single-airport (PEK / PVG) and metro-group (BJS / SHA) codes.View on GitHub (pinned to 49907e53dc)
Solutions
- Rewrite the date as YYYY-MM-DD with zero-padded month/day, e.g. 2026-09-01
- Use `date -d 'tomorrow' +%F` (GNU) to generate a compliant string
- Do not rely on the library to coerce formats — validate before calling
- Check for stray whitespace or quotes around the value
Example fix
// before --depart 9/1/2026 // after --depart 2026-09-01
Defensive patterns
Strategy: validation
Validate before calling
const ISO_RE = /^\d{4}-\d{2}-\d{2}$/;
if (!ISO_RE.test(dateInput)) throw new Error(`date must be YYYY-MM-DD, got ${dateInput}`); Type guard
function isIsoDateString(v) {
return typeof v === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(v);
} Try / catch
try {
const date = parseIsoDate('depart', raw);
} catch (err) {
if (err instanceof ArgumentError && /must be YYYY-MM-DD/.test(err.message)) {
// show usage example: 2026-09-01
}
throw err;
} Prevention
- Always format dates as zero-padded YYYY-MM-DD
- Use `date +%F` or toISOString().slice(0,10) to generate dates
- Never pass human phrases like 'tomorrow' directly
- Normalize slashes/dots to dashes before invoking
When it happens
Trigger: Calling parseIsoDate(name, raw) with values like '2026/09/01', '09-01-2026', '2026-9-1', 'tomorrow', or a Date object stringified — anything not exactly four digits, dash, two digits, dash, two digits.
Common situations: US-style date format habit (MM/DD/YYYY); user types a human phrase like 'next Friday'; locale-formatted date pasted from a calendar app; missing zero-padding.
Related errors
- ${label} is required (YYYY-MM-DD)
- --${name} has invalid month/day: ${value}
- huodongxing ${label} must be a valid YYYY-MM-DD date
- Date must be YYYY-MM-DD: ${date}
- --${name} must be YYYY-MM-DD, got ${JSON.stringify(raw)}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/1b69411a65647025.
Report an issue: GitHub.