RocketChat/Rocket.Chat · error · Error
Invalid date range
Error message
Invalid date range
What it means
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.
Source
Thrown at apps/meteor/ee/server/apps/communication/endpoints/lib/makeAppLogsQuery.ts:53
if (queryParams.method) {
query.method = queryParams.method;
}
if (queryParams.instanceId) {
query.instanceId = queryParams.instanceId;
}
if (queryParams.startDate) {
query._updatedAt = {
$gte: new Date(queryParams.startDate),
};
}
if (queryParams.endDate) {
const endDate = new Date(queryParams.endDate);
if (query._updatedAt?.$gte && query._updatedAt.$gte >= endDate) {
throw new Error('Invalid date range');
}
query._updatedAt = {
...(query._updatedAt || {}),
$lte: endDate,
};
}
return query;
}
View on GitHub (pinned to f9d3ec372b)
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.
Example fix
// before ?startDate=2026-01-10T00:00:00Z&endDate=2026-01-05T00:00:00Z // after - correct order ?startDate=2026-01-05T00:00:00Z&endDate=2026-01-10T00:00:00Z
Defensive patterns
Strategy: validation
Validate before calling
function validateDateRange(startDate?: string, endDate?: string) {
if (!startDate || !endDate) return true;
const start = new Date(startDate).getTime();
const end = new Date(endDate).getTime();
if (Number.isNaN(start) || Number.isNaN(end)) return false;
return start < end;
}
if (!validateDateRange(query.startDate, query.endDate)) {
throw new Error('startDate must be earlier than endDate');
} Type guard
const isValidDateRange = (start?: string, end?: string): boolean => {
if (!start || !end) return true;
const s = Date.parse(start);
const e = Date.parse(end);
return !Number.isNaN(s) && !Number.isNaN(e) && s < e;
}; Try / catch
try {
await fetchAppLogs(query);
} catch (e) {
if (e instanceof Error && e.message === 'Invalid date range') {
showUserError('Pick an end date after the start date.');
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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'.
Related errors
- Invalid Api parameter provided, it must be a valid IApi obje
- Invalid command parameter provided, must be a string.
- Invalid Slash Command parameter provided, it must be a valid
- The environmental variable "${envVarName}" is not readable.
- auth option should be of the form "username:password"
AI-assisted analysis of RocketChat/Rocket.Chat@f9d3ec372b (2026-08-12).
Data as JSON: /api/errors/e73f442e9ca9ce03.
Report an issue: GitHub.