jackwener/OpenCLI · error · ArgumentError
${label} is required (YYYY-MM-DD)
Error message
${label} is required (YYYY-MM-DD) What it means
normalizeDate validates checkin/checkout inputs: the value must be a non-empty string. This ArgumentError is thrown when the date option is missing, null, undefined, or an empty/whitespace-only string. The library cannot infer dates, so the caller must always supply them in YYYY-MM-DD form (format mismatches throw a different message from the same function).
Source
Thrown at clis/booking/search.js:37
return n;
}
function normalizeNonNegativeInt(value, defaultValue, label, max) {
const raw = value ?? defaultValue;
const n = Number(raw);
if (!Number.isInteger(n) || n < 0) {
throw new ArgumentError(`${label} must be a non-negative integer`);
}
if (typeof max === 'number' && n > max) {
throw new ArgumentError(`${label} must be <= ${max}`);
}
return n;
}
function normalizeDate(value, label) {
const v = String(value || '').trim();
if (!v) {
throw new ArgumentError(`${label} is required (YYYY-MM-DD)`);
}
if (!DATE_RE.test(v)) {
throw new ArgumentError(`${label} must be YYYY-MM-DD, got ${JSON.stringify(value)}`);
}
const [year, month, day] = v.split('-').map(Number);
const d = new Date(Date.UTC(year, month - 1, day));
if (
Number.isNaN(d.getTime()) ||
d.getUTCFullYear() !== year ||
d.getUTCMonth() !== month - 1 ||
d.getUTCDate() !== day
) {
throw new ArgumentError(`${label} is not a valid calendar date: ${v}`);
}
return v;
}
function normalizeCurrency(value) {View on GitHub (pinned to 49907e53dc)
Solutions
- Supply both checkin and checkout as YYYY-MM-DD strings, e.g. --checkin 2026-09-01 --checkout 2026-09-05.
- If sourcing from env/config, check the variable exists before invoking: if (!process.env.CHECKIN) fail fast.
- Ensure the value is a non-empty trimmed string (String(value || '').trim() must be truthy).
- Also ensure checkout >= checkin so a later step does not reject the range.
Example fix
// before
const checkin = process.env.CHECKIN; // undefined
await bookingSearch({ checkin, checkout: '2026-09-05' }); // throws: checkin is required (YYYY-MM-DD)
// after
if (!process.env.CHECKIN) throw new Error('CHECKIN env var required');
await bookingSearch({ checkin: process.env.CHECKIN, checkout: '2026-09-05' }); Defensive patterns
Strategy: validation
Validate before calling
const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
function requireDate(value, label) {
const v = String(value ?? '').trim();
if (!v) throw new Error(`${label} is required (YYYY-MM-DD)`);
if (!DATE_RE.test(v)) throw new Error(`${label} must be YYYY-MM-DD`);
return v;
}
const checkin = requireDate(opts.checkin, 'checkin');
const checkout = requireDate(opts.checkout, 'checkout'); Type guard
function isNonEmptyDateString(v) {
return typeof v === 'string' && v.trim().length > 0;
} Try / catch
try {
await bookingSearch({ checkin, checkout });
} catch (e) {
if (e instanceof ArgumentError && e.message.includes('is required (YYYY-MM-DD)')) {
console.error(`Missing date option: ${e.message.split(' is required')[0]}`); process.exitCode = 2;
} else throw e;
} Prevention
- Mark checkin/checkout as required options in your own CLI parser so absence fails at parse time.
- Verify env/config date variables are set before invoking.
- Validate the YYYY-MM-DD format (and calendar validity) at input boundaries.
- Always pass dates as trimmed strings; never rely on null/undefined coercion.
When it happens
Trigger: Calling search without --checkin/--checkout; passing checkin: null, '', ' ', or a value that stringifies to empty; a variable that is undefined because an upstream fetch of the user's dates failed.
Common situations: Interactive flows where the user skipped the date prompt; scripts relying on an env var like CHECKIN_DATE that was never set; building CLI args conditionally and dropping the flag; timezone bugs producing empty strings from form data.
Understand the failure class
Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 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/1131157a72c57564.
Report an issue: GitHub.