{"record":{"id":"1131157a72c57564","repo":"jackwener/OpenCLI","slug":"label-is-required-yyyy-mm-dd","errorCode":null,"errorMessage":"${label} is required (YYYY-MM-DD)","messagePattern":"(.+?) is required \\(YYYY-MM-DD\\)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/booking/search.js","lineNumber":37,"sourceCode":"  return n;\n}\n\nfunction normalizeNonNegativeInt(value, defaultValue, label, max) {\n  const raw = value ?? defaultValue;\n  const n = Number(raw);\n  if (!Number.isInteger(n) || n < 0) {\n    throw new ArgumentError(`${label} must be a non-negative integer`);\n  }\n  if (typeof max === 'number' && n > max) {\n    throw new ArgumentError(`${label} must be <= ${max}`);\n  }\n  return n;\n}\n\nfunction normalizeDate(value, label) {\n  const v = String(value || '').trim();\n  if (!v) {\n    throw new ArgumentError(`${label} is required (YYYY-MM-DD)`);\n  }\n  if (!DATE_RE.test(v)) {\n    throw new ArgumentError(`${label} must be YYYY-MM-DD, got ${JSON.stringify(value)}`);\n  }\n  const [year, month, day] = v.split('-').map(Number);\n  const d = new Date(Date.UTC(year, month - 1, day));\n  if (\n    Number.isNaN(d.getTime()) ||\n    d.getUTCFullYear() !== year ||\n    d.getUTCMonth() !== month - 1 ||\n    d.getUTCDate() !== day\n  ) {\n    throw new ArgumentError(`${label} is not a valid calendar date: ${v}`);\n  }\n  return v;\n}\n\nfunction normalizeCurrency(value) {","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/booking/search.js#L19-L55","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst checkin = process.env.CHECKIN; // undefined\nawait bookingSearch({ checkin, checkout: '2026-09-05' }); // throws: checkin is required (YYYY-MM-DD)\n// after\nif (!process.env.CHECKIN) throw new Error('CHECKIN env var required');\nawait bookingSearch({ checkin: process.env.CHECKIN, checkout: '2026-09-05' });","handlingStrategy":"validation","validationCode":"const DATE_RE = /^\\d{4}-\\d{2}-\\d{2}$/;\nfunction requireDate(value, label) {\n  const v = String(value ?? '').trim();\n  if (!v) throw new Error(`${label} is required (YYYY-MM-DD)`);\n  if (!DATE_RE.test(v)) throw new Error(`${label} must be YYYY-MM-DD`);\n  return v;\n}\nconst checkin = requireDate(opts.checkin, 'checkin');\nconst checkout = requireDate(opts.checkout, 'checkout');","typeGuard":"function isNonEmptyDateString(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  await bookingSearch({ checkin, checkout });\n} catch (e) {\n  if (e instanceof ArgumentError && e.message.includes('is required (YYYY-MM-DD)')) {\n    console.error(`Missing date option: ${e.message.split(' is required')[0]}`); process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["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."],"tags":["argument-validation","cli","missing-argument","date-format"],"backgroundTag":"missing-required-parameter","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}