{"record":{"id":"dc02dd796186042c","repo":"jackwener/OpenCLI","slug":"name-is-required-yyyy-mm-dd","errorCode":null,"errorMessage":"--${name} is required (YYYY-MM-DD)","messagePattern":"--(.+?) is required \\(YYYY-MM-DD\\)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/ctrip/utils.js","lineNumber":210,"sourceCode":"        countryName: item?.countryName ? String(item.countryName).trim() : null,\n        lat,\n        lon,\n        score: firstNonZero(item?.commentScore, item?.cStar),\n        url: buildUrl(item),\n    };\n}\n\n/* --------- Helpers shared by hotel-search / flight (browser-context) ---------- */\n\nconst ISO_DATE_RE = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\n\n/**\n * Validate YYYY-MM-DD and return the canonical string. Rejects out-of-range\n * month/day, malformed input, and silent NaN. Does NOT coerce or shift timezones.\n */\nexport function parseIsoDate(name, raw) {\n    if (raw === undefined || raw === null || raw === '' || String(raw).trim() === '') {\n        throw new ArgumentError(`--${name} is required (YYYY-MM-DD)`);\n    }\n    const value = String(raw);\n    const m = ISO_DATE_RE.exec(value);\n    if (!m) {\n        throw new ArgumentError(`--${name} must be YYYY-MM-DD, got ${JSON.stringify(raw)}`);\n    }\n    const year = Number(m[1]);\n    const month = Number(m[2]);\n    const day = Number(m[3]);\n    if (month < 1 || month > 12 || day < 1 || day > 31) {\n        throw new ArgumentError(`--${name} has invalid month/day: ${value}`);\n    }\n    // Cross-check via UTC date math so 2026-02-30 doesn't pass.\n    const parsed = new Date(Date.UTC(year, month - 1, day));\n    if (parsed.getUTCFullYear() !== year || parsed.getUTCMonth() !== month - 1 || parsed.getUTCDate() !== day) {\n        throw new ArgumentError(`--${name} is not a real calendar date: ${value}`);\n    }\n    return value;","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/ctrip/utils.js#L192-L228","documentation":"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.","triggerScenarios":"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 \"  \").","commonSituations":"User forgets the required date flag; shell variable holding the date is unset/empty; script passes empty string after a failed lookup.","solutions":["Pass the flag explicitly, e.g. --checkin 2026-09-01","Check that the shell variable feeding the flag is not empty","Consult the command's help to see which date flags are required","Default the value in your wrapper script before invoking"],"exampleFix":"// before\nctrip hotels --city 1 --checkin \"$CHECKIN\"\n# after\nCHECKIN=\"${CHECKIN:-$(date -d '+1 day' +%F)}\"\nctrip hotels --city 1 --checkin \"$CHECKIN\"","handlingStrategy":"validation","validationCode":"function requireIsoDateFlag(value, name) {\n  if (value == null || String(value).trim() === '') {\n    throw new Error(`--${name} is required (YYYY-MM-DD)`);\n  }\n  return value;\n}","typeGuard":"function isNonEmptyString(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  const date = parseIsoDate('checkin', raw);\n} catch (err) {\n  if (err instanceof ArgumentError && /is required/.test(err.message)) {\n    // fall back to a default date, e.g. tomorrow\n  }\n  throw err;\n}","preventionTips":["Always pass required date flags explicitly","Default empty env vars in wrapper scripts before invoking","Check command --help to see which flags are mandatory","Fail fast in scripts when a computed date is empty"],"tags":["argument-validation","cli","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}