{"record":{"id":"6d4bdf143f2479a3","repo":"jackwener/OpenCLI","slug":"name-is-required-yyyy-mm-dd-6d4bdf","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/trip/utils.js","lineNumber":30,"sourceCode":"const MAX_LIMIT = 50;\nconst ISO_DATE_RE = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\nconst POI_SEARCH_ENDPOINT = 'https://www.trip.com/restapi/soa2/14427/poiSearch';\nconst PACKAGE_SEARCH_ENDPOINT = 'https://www.trip.com/restapi/soa2/19866/FlightSelectSearch';\n\nexport function parseIataCode(name, raw) {\n    if (raw === undefined || raw === null || raw === '') {\n        throw new ArgumentError(`--${name} is required (3-letter IATA code, e.g. LON, NYC)`);\n    }\n    const value = String(raw).trim().toUpperCase();\n    if (!/^[A-Z]{3}$/.test(value)) {\n        throw new ArgumentError(`--${name} must be a 3-letter IATA code, got ${JSON.stringify(raw)}`);\n    }\n    return value;\n}\n\nexport function parseIsoDate(name, raw) {\n    if (raw === undefined || raw === null || raw === '') {\n        throw new ArgumentError(`--${name} is required (YYYY-MM-DD)`);\n    }\n    const value = String(raw).trim();\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":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trip/utils.js#L12-L48","documentation":"parseIsoDate requires a date argument in YYYY-MM-DD format; this error is thrown when the argument is missing entirely (undefined, null, or empty string after conversion). It exists so CLI commands fail fast with a message naming the exact flag and expected format.","triggerScenarios":"Calling depart, ret, date, checkin, or checkout (which delegate to parseIsoDate) without the flag at all, or with --date '' / an unset variable that evaluates to empty.","commonSituations":"User forgot the flag; an env var or config value backing the argument is unset; a script interpolates an empty variable into the command line; whitespace-only value in a config file.","solutions":["Supply the flag with a YYYY-MM-DD value, e.g. --depart 2026-10-01","Check the command's help output to see which date flags are required","If the value comes from a variable/config, verify it is set and non-empty before invoking","Default the value in a wrapper script, e.g. DEPART=$(date -d '+7 days' +%F)"],"exampleFix":"// before\nclis-trip hotels --city-id 338 --checkout 2026-10-05\n// after\nclis-trip hotels --city-id 338 --checkin 2026-10-01 --checkout 2026-10-05","handlingStrategy":"validation","validationCode":"if (depart === undefined || depart === null || String(depart).trim() === '') {\n  throw new Error('--depart is required (YYYY-MM-DD)');\n}","typeGuard":"function isProvided(v) {\n  return v !== undefined && v !== null && String(v).trim() !== '';\n}","tryCatchPattern":"try {\n  runTripCli(['flights', '--depart', depart]);\n} catch (err) {\n  if (err instanceof ArgumentError && /is required \\(YYYY-MM-DD\\)/.test(err.message)) {\n    console.error(`Missing date flag: ${err.message}`);\n    process.exitCode = 2;\n  } else throw err;\n}","preventionTips":["List all required flags in your wrapper scripts and assert them before invocation","Default optional dates explicitly (e.g. tomorrow's date) instead of leaving them unset","Check config/env sources for empty values before interpolation","Use ${VAR:?msg} in bash to fail early on unset variables"],"tags":["cli","missing-argument","date"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}