{"record":{"id":"1be8aa17721f3e4a","repo":"RocketChat/Rocket.Chat","slug":"the-name-parameter-must-be-a-valid-date","errorCode":null,"errorMessage":"The \"${name}\" parameter must be a valid date.","messagePattern":"The \"(.+?)\" parameter must be a valid date\\.","errorType":"http","errorClass":"Error","httpStatus":400,"severity":"warning","filePath":"apps/meteor/ee/server/api/audit.ts","lineNumber":404,"sourceCode":"\t},\n\trequired: ['messages', 'success'],\n\tadditionalProperties: false,\n});\n\nconst auditErrorResponseSchema = ajv.compile({\n\ttype: 'object',\n\tproperties: {\n\t\tsuccess: { type: 'boolean', enum: [false] },\n\t\terror: { type: 'string' },\n\t\terrorType: { type: 'string' },\n\t},\n\trequired: ['success', 'error'],\n});\n\nconst parseDateOrFail = (value: string, name: string): Date => {\n\tconst ts = Date.parse(value);\n\tif (Number.isNaN(ts)) {\n\t\tthrow new Error(`The \"${name}\" parameter must be a valid date.`);\n\t}\n\treturn new Date(ts);\n};\n\nAPI.v1.get(\n\t'audit.auditions',\n\t{\n\t\tauthRequired: true,\n\t\tpermissionsRequired: ['can-audit-log'],\n\t\tquery: isAuditAuditionsProps,\n\t\tlicense: ['auditing'],\n\t\trateLimiterOptions: { numRequestsAllowed: 10, intervalTimeInMS: 60000 },\n\t\tresponse: {\n\t\t\t200: auditAuditionsResponseSchema,\n\t\t\t400: auditErrorResponseSchema,\n\t\t\t401: validateUnauthorizedErrorResponse,\n\t\t\t403: validateForbiddenErrorResponse,\n\t\t},","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/ee/server/api/audit.ts#L386-L422","documentation":"Thrown by parseDateOrFail in the audit.auditions endpoint handler when Date.parse() returns NaN for the startDate or endDate query parameter. The helper is called for both queryParams.startDate and queryParams.endDate; the failing parameter name is interpolated into the message so the caller knows which one is malformed.","triggerScenarios":"Calling GET /api/v1/audit.auditions with a startDate or endDate that is not ISO-8601/RFC2822 parseable (e.g. '2024-13-45', 'yesterday', empty string, 'NaN'); passing a numeric timestamp as a non-string; localized date format Date.parse cannot handle.","commonSituations":"Client sends locale-formatted dates (DD/MM/YYYY) instead of ISO; empty/null date params; copy-paste typo; timezone-less relative strings.","solutions":["Send startDate/endDate as full ISO-8601 strings with timezone (e.g. '2024-01-01T00:00:00.000Z').","Validate/normalize the date client-side before the request and fall back to a sane default.","If relative ranges are needed, compute the ISO string in code, do not pass words like 'yesterday'."],"exampleFix":"// before\nGET /api/v1/audit.auditions?startDate=yesterday&endDate=2024-01-01\n\n// after\nconst start = new Date(Date.now() - 86400000).toISOString();\nconst end = new Date().toISOString();\nGET `/api/v1/audit.auditions?startDate=${start}&endDate=${end}`","handlingStrategy":"validation","validationCode":"// Validate ISO date strings before calling audit.auditions.\nconst isValidDate = (v: string) => !Number.isNaN(Date.parse(v));\nif (!isValidDate(startDate) || !isValidDate(endDate)) {\n  throw new Error('startDate and endDate must be valid ISO-8601 dates');\n}\nGET `/api/v1/audit.auditions?startDate=${encodeURIComponent(new Date(startDate).toISOString())}&endDate=${encodeURIComponent(new Date(endDate).toISOString())}`","typeGuard":"const isParseableDate = (v: unknown): v is string =>\n  typeof v === 'string' && !Number.isNaN(Date.parse(v));","tryCatchPattern":"try {\n  await fetch(`/api/v1/audit.auditions?startDate=${start}&endDate=${end}`);\n} catch (e) {\n  if (/must be a valid date/.test(e?.message)) { /* normalize inputs to ISO and retry */ }\n  else throw e;\n}","preventionTips":["Always send ISO-8601 with explicit timezone (UTC 'Z').","Normalize locale formats to ISO client-side before the request.","Never pass relative words (e.g. 'yesterday'); compute the ISO string in code."],"tags":["ee","server","rest-api","audit","validation","date"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}