{"record":{"id":"e73f442e9ca9ce03","repo":"RocketChat/Rocket.Chat","slug":"invalid-date-range","errorCode":null,"errorMessage":"Invalid date range","messagePattern":"Invalid date range","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"apps/meteor/ee/server/apps/communication/endpoints/lib/makeAppLogsQuery.ts","lineNumber":53,"sourceCode":"\tif (queryParams.method) {\n\t\tquery.method = queryParams.method;\n\t}\n\n\tif (queryParams.instanceId) {\n\t\tquery.instanceId = queryParams.instanceId;\n\t}\n\n\tif (queryParams.startDate) {\n\t\tquery._updatedAt = {\n\t\t\t$gte: new Date(queryParams.startDate),\n\t\t};\n\t}\n\n\tif (queryParams.endDate) {\n\t\tconst endDate = new Date(queryParams.endDate);\n\n\t\tif (query._updatedAt?.$gte && query._updatedAt.$gte >= endDate) {\n\t\t\tthrow new Error('Invalid date range');\n\t\t}\n\n\t\tquery._updatedAt = {\n\t\t\t...(query._updatedAt || {}),\n\t\t\t$lte: endDate,\n\t\t};\n\t}\n\n\treturn query;\n}\n","sourceCodeStart":35,"sourceCodeEnd":64,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/ee/server/apps/communication/endpoints/lib/makeAppLogsQuery.ts#L35-L64","documentation":"Thrown by makeAppLogsQuery (used by the EE app-logs API) when the caller supplies both startDate and endDate query parameters and the parsed startDate is greater than or equal to the parsed endDate. The function builds a Mongo _updatedAt range filter ($gte start, $lte end); an inverted or zero-width range is rejected instead of silently returning an empty result.","triggerScenarios":"Any app-logs request whose query string contains startDate and endDate where new Date(startDate) >= new Date(endDate), e.g. ?startDate=2026-01-10&endDate=2026-01-01, or identical timestamps (equality also throws because $gte >= $lte). Malformed strings that parse to Invalid Date also end up comparing as false in JS, but equal/inverted valid dates are the direct trigger.","commonSituations":"Dashboard date-picker sending the fields in the wrong order; timezone confusion where an end-of-day UTC end date lands before a local-time start date; copy-paste of the same timestamp for both bounds; client building params from two independent inputs without cross-validation.","solutions":["Swap or correct the parameters so startDate is strictly earlier than endDate and retry.","Validate/normalize both dates on the client before sending: parse with new Date(), compare, and only append endDate when it is strictly greater than startDate.","If both bounds are equal intentionally, drop endDate (a single startDate gives an open-ended $gte filter) instead of sending an empty range.","Check timezone handling (append explicit offsets or use ISO 8601 with Z) so server-side parsing does not invert the order."],"exampleFix":"// before\nconst qs = `?startDate=${start}&endDate=${end}`; // start >= end -> \"Invalid date range\"\n\n// after\nconst qs = new URLSearchParams();\nqs.set('startDate', start.toISOString());\nif (end.getTime() > start.getTime()) qs.set('endDate', end.toISOString());","handlingStrategy":"validation","validationCode":"function isValidLogRange(start?: string, end?: string): boolean {\n  if (!start || !end) return true;\n  const s = new Date(start).getTime();\n  const e = new Date(end).getTime();\n  return Number.isFinite(s) && Number.isFinite(e) && s < e;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const logs = await fetchAppLogs({ startDate, endDate });\n} catch (e) {\n  if (e instanceof Error && e.message === 'Invalid date range') {\n    // fix the picker bounds and re-run; retrying the same params is pointless\n  }\n}","preventionTips":["Cross-validate date pickers client-side: end must be strictly after start.","Send ISO 8601 strings with explicit timezone offsets.","Omit endDate when it equals startDate instead of sending an empty range."],"tags":["validation","date-range","query-params","app-logs","enterprise"],"backgroundTag":"invalid-date-range","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}