jackwener/OpenCLI · error · ArgumentError

--${name} is required (YYYY-MM-DD)

Error message

--${name} is required (YYYY-MM-DD)

What it means

parseIsoDate throws this ArgumentError when the date option it validates is missing entirely (undefined, null, empty string, or whitespace-only). The CLI requires explicit YYYY-MM-DD dates for flags like --date, --depart, --checkin etc., and does not guess defaults.

Source

Thrown at clis/ctrip/utils.js:210

        countryName: item?.countryName ? String(item.countryName).trim() : null,
        lat,
        lon,
        score: firstNonZero(item?.commentScore, item?.cStar),
        url: buildUrl(item),
    };
}

/* --------- 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;

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass the flag explicitly, e.g. --checkin 2026-09-01
  2. Check that the shell variable feeding the flag is not empty
  3. Consult the command's help to see which date flags are required
  4. Default the value in your wrapper script before invoking

Example fix

// before
ctrip hotels --city 1 --checkin "$CHECKIN"
# after
CHECKIN="${CHECKIN:-$(date -d '+1 day' +%F)}"
ctrip hotels --city 1 --checkin "$CHECKIN"
Defensive patterns

Strategy: validation

Validate before calling

function requireIsoDateFlag(value, name) {
  if (value == null || String(value).trim() === '') {
    throw new Error(`--${name} is required (YYYY-MM-DD)`);
  }
  return value;
}

Type guard

function isNonEmptyString(v) {
  return typeof v === 'string' && v.trim().length > 0;
}

Try / catch

try {
  const date = parseIsoDate('checkin', raw);
} catch (err) {
  if (err instanceof ArgumentError && /is required/.test(err.message)) {
    // fall back to a default date, e.g. tomorrow
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling parseIsoDate(name, raw) from commands using --date/--depart/--ret/--checkin/--checkout when the flag was omitted or passed an empty value (e.g. --checkin "" or --checkin " ").

Common situations: User forgets the required date flag; shell variable holding the date is unset/empty; script passes empty string after a failed lookup.

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


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/dc02dd796186042c. Report an issue: GitHub.