jackwener/OpenCLI · error · ArgumentError
huodongxing ${label} must be a valid YYYY-MM-DD date
Error message
huodongxing ${label} must be a valid YYYY-MM-DD date What it means
requireYmdArg validates optional date filters (labels 'date' and 'dateTo') for the huodongxing events command. If a non-empty value is supplied that doesn't match a strict, real YYYY-MM-DD calendar date (validated by parseYmd, including month/day range checks via Date round-trip), it throws this ArgumentError. Empty values are allowed and mean 'no filter'.
Source
Thrown at clis/huodongxing/events.js:65
const year = Number(match[1]);
const month = Number(match[2]);
const day = Number(match[3]);
const date = new Date(Date.UTC(year, month - 1, day));
if (
date.getUTCFullYear() !== year
|| date.getUTCMonth() !== month - 1
|| date.getUTCDate() !== day
) {
return null;
}
return dateOrdinal(year, month, day);
}
function requireYmdArg(value, label) {
const text = cleanText(value);
if (!text) return '';
if (parseYmd(text) == null) {
throw new ArgumentError(`huodongxing ${label} must be a valid YYYY-MM-DD date`);
}
return text;
}
function requireDateRangeArgs(args = {}) {
const date = requireYmdArg(args.date, 'date');
const dateTo = requireYmdArg(args.dateTo, 'dateTo');
if (date && dateTo && parseYmd(date) > parseYmd(dateTo)) {
throw new ArgumentError('huodongxing date must be <= dateTo');
}
return { date, dateTo };
}
function unwrapEvaluateResult(payload) {
if (payload && !Array.isArray(payload) && typeof payload === 'object' && 'session' in payload && 'data' in payload) {
return payload.data;
}
return payload;View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a real calendar date in exact YYYY-MM-DD form, e.g. date: '2024-01-15'.
- Convert Date objects before calling: d.toISOString().slice(0, 10).
- Pre-validate with a regex + Date round-trip at the call site and reject early with a clear message.
- If the filter is optional, pass undefined/'' instead of a placeholder string like 'N/A'.
Example fix
// before
await events({ date: new Date() }); // Date object -> ArgumentError
await events({ date: '2024-13-01' }); // invalid month -> ArgumentError
// after
await events({ date: new Date().toISOString().slice(0, 10) }); // '2026-08-28' Defensive patterns
Strategy: validation
Validate before calling
function isValidYmd(value) {
const m = /^\d{4}-\d{2}-\d{2}$/.exec(String(value ?? '').trim());
if (!m) return false;
const d = new Date(Date.UTC(+m[0].slice(0,4), +m[0].slice(5,7) - 1, +m[0].slice(8,10)));
return d.toISOString().slice(0, 10) === String(value).trim();
}
if (userDate && !isValidYmd(userDate)) throw new Error('date must be a valid YYYY-MM-DD date'); Type guard
function isYmdString(v) {
return typeof v === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(v) && isValidYmd(v);
} Try / catch
try {
await events({ date, dateTo });
} catch (err) {
if (err instanceof ArgumentError && err.message.includes('YYYY-MM-DD')) {
console.error(`Bad date filter: ${date ?? dateTo}. Use e.g. 2026-08-28.`);
} else throw err;
} Prevention
- Convert Date objects with toISOString().slice(0, 10) before passing.
- Always zero-pad month/day (2026-08-05, not 2026-8-5).
- Never pass Date objects, ISO timestamps, or locale-formatted strings directly.
- Validate calendar validity (e.g. 2024-02-30 fails) with a Date round-trip, not just the regex.
When it happens
Trigger: date('2024/01/15') (slashes instead of dashes), date('15-01-2024') (wrong order), date('2024-13-01') (month 13), date('2024-02-30') (impossible day), date('tomorrow') — any non-empty value failing the ^\d{4}-\d{2}-\d{2}$ pattern plus real-date check.
Common situations: Passing a JS Date object or ISO timestamp ('2024-01-15T10:00:00Z') instead of a date-only string; locale-formatted dates (MM/DD/YYYY); user input from forms not normalized; off-by-one month values from zero-based month math.
Related errors
- ${label} is required (YYYY-MM-DD)
- --${name} must be YYYY-MM-DD, got ${JSON.stringify(raw)}
- --${name} has invalid month/day: ${value}
- 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/72707c534d43ba5b.
Report an issue: GitHub.