RocketChat/Rocket.Chat · error
Invalid date range
Error message
Invalid date range
What it means
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.
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.
Example fix
// before
const qs = `?startDate=${start}&endDate=${end}`; // start >= end -> "Invalid date range"
// after
const qs = new URLSearchParams();
qs.set('startDate', start.toISOString());
if (end.getTime() > start.getTime()) qs.set('endDate', end.toISOString()); Defensive patterns
Strategy: validation
Validate before calling
function isValidLogRange(start?: string, end?: string): boolean {
if (!start || !end) return true;
const s = new Date(start).getTime();
const e = new Date(end).getTime();
return Number.isFinite(s) && Number.isFinite(e) && s < e;
} Try / catch
try {
const logs = await fetchAppLogs({ startDate, endDate });
} catch (e) {
if (e instanceof Error && e.message === 'Invalid date range') {
// fix the picker bounds and re-run; retrying the same params is pointless
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/e73f442e9ca9ce03.
Report an issue: GitHub.
Appendix: 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 b2c16d5842)