{"record":{"id":"7ff7c536b19d03b3","repo":"jackwener/OpenCLI","slug":"name-must-be-yyyy-mm-dd-got-json-stringify-7ff7c5","errorCode":null,"errorMessage":"--${name} must be YYYY-MM-DD, got ${JSON.stringify(raw)}","messagePattern":"--(.+?) must be YYYY-MM-DD, got (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/trip/utils.js","lineNumber":35,"sourceCode":"export 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;\n}\n\nexport function parseListLimit(raw, fallback = 20) {\n    if (raw === undefined || raw === null || raw === '') return fallback;\n    const parsed = Number(raw);","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trip/utils.js#L17-L53","documentation":"parseIsoDate rejects a provided date value that does not match the strict YYYY-MM-DD pattern (ISO_DATE_RE). The value must be digits in the exact form year-month-day; other formats or stray characters are rejected. This keeps downstream URL building and date math working on a canonical format.","triggerScenarios":"Passing dates like '01/10/2026', '2026-1-5', '2026/10/01', 'Oct 5 2026', '2026-10-01T00:00', or a full timestamp string to depart/ret/date/checkin/checkout.","commonSituations":"US-style MM/DD/YYYY habits; locale-formatted dates pasted from a calendar app; Date objects stringified with time components; spreadsheets exporting dates with slashes.","solutions":["Reformat the value to strict YYYY-MM-DD, e.g. 2026-10-01","Zero-pad month and day to two digits (2026-1-5 -> 2026-01-05)","Strip time components if passing a Date/ISO timestamp: slice(0,10) or toISOString().slice(0,10)","Avoid locale-dependent formatting; use explicit yyyy-MM-dd formatting"],"exampleFix":"// before\nclis-trip flights --from LON --to NYC --depart 10/01/2026\n// after\nclis-trip flights --from LON --to NYC --depart 2026-10-01","handlingStrategy":"validation","validationCode":"const ISO_DATE_RE = /^\\d{4}-\\d{2}-\\d{2}$/;\nif (!ISO_DATE_RE.test(String(depart).trim())) {\n  throw new Error(`--depart must be YYYY-MM-DD, got ${JSON.stringify(depart)}`);\n}","typeGuard":"function isIsoDateString(v) {\n  return typeof v === 'string' && /^\\d{4}-\\d{2}-\\d{2}$/.test(v.trim());\n}","tryCatchPattern":"try {\n  runTripCli(['flights', '--depart', depart]);\n} catch (err) {\n  if (err instanceof ArgumentError && /must be YYYY-MM-DD/.test(err.message)) {\n    console.error(`Reformat date as YYYY-MM-DD: ${err.message}`);\n    process.exitCode = 2;\n  } else throw err;\n}","preventionTips":["Always generate dates with toISOString().slice(0,10) or explicit yyyy-MM-dd formatting","Never pass locale-formatted or Date.toString() output directly","Zero-pad month and day to two digits","Normalize all dates at your system boundary before they reach the CLI"],"tags":["cli","argument-validation","date-format"],"backgroundTag":"date-format-mismatch","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}