{"record":{"id":"e73f442e9ca9ce03","repo":"RocketChat/Rocket.Chat","slug":"invalid-date-range","errorCode":null,"errorMessage":"Invalid date range","messagePattern":"Invalid date range","errorType":"exception","errorClass":"Error","httpStatus":null,"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/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/ee/server/apps/communication/endpoints/lib/makeAppLogsQuery.ts#L35-L64","documentation":"Thrown by makeAppLogsQuery when both startDate and endDate query params are supplied and the parsed startDate (as a Date) is greater than or equal to the parsed endDate. The function builds a Mongo _updatedAt range filter and rejects inverted/overlapping ranges before querying the app logs collection. Endpoint-layer AJV validation already requires date-time formatted strings, so this fires only when the strings parse but the range is logically invalid.","triggerScenarios":"Calling the app logs endpoint (GET /api/v1/apps/logs or the EE app-logs-export variant) with startDate >= endDate, e.g. startDate=2026-01-10T00:00:00Z and endDate=2026-01-05T00:00:00Z. Swapping the two fields, or sending the same instant for both, triggers it.","commonSituations":"A frontend date-picker that lets the user pick 'from' after 'to'; timezone confusion where endDate is converted to an earlier UTC instant than startDate; copy-paste of date strings from different locales; automated scripts that default both bounds to 'now'.","solutions":["Ensure startDate is strictly earlier than endDate before submitting the request.","Swap the two values if they are reversed.","If you want a single-day window, set endDate to the end of that day (23:59:59) so it is greater than startDate.","Validate client-side: if (new Date(start) >= new Date(end)) show a 'range invalid' message instead of sending."],"exampleFix":"// before\n?startDate=2026-01-10T00:00:00Z&endDate=2026-01-05T00:00:00Z\n\n// after - correct order\n?startDate=2026-01-05T00:00:00Z&endDate=2026-01-10T00:00:00Z","handlingStrategy":"validation","validationCode":"function validateDateRange(startDate?: string, endDate?: string) {\n  if (!startDate || !endDate) return true;\n  const start = new Date(startDate).getTime();\n  const end = new Date(endDate).getTime();\n  if (Number.isNaN(start) || Number.isNaN(end)) return false;\n  return start < end;\n}\n\nif (!validateDateRange(query.startDate, query.endDate)) {\n  throw new Error('startDate must be earlier than endDate');\n}","typeGuard":"const isValidDateRange = (start?: string, end?: string): boolean => {\n  if (!start || !end) return true;\n  const s = Date.parse(start);\n  const e = Date.parse(end);\n  return !Number.isNaN(s) && !Number.isNaN(e) && s < e;\n};","tryCatchPattern":"try {\n  await fetchAppLogs(query);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Invalid date range') {\n    showUserError('Pick an end date after the start date.');\n  }\n}","preventionTips":["Always validate startDate < endDate on the client before sending the request.","Use a date picker that prevents inverted selections.","When sending a single-day filter, set endDate to end-of-day (23:59:59Z).","Normalize both dates to UTC before comparison to avoid timezone inversion."],"tags":["apps-engine","logs","validation","date-range"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}