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

  1. Ensure startDate is strictly earlier than endDate before submitting the request.
  2. Swap the two values if they are reversed.
  3. If you want a single-day window, set endDate to the end of that day (23:59:59) so it is greater than startDate.
  4. 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

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


AI-assisted analysis of RocketChat/Rocket.Chat@f9d3ec372b (2026-08-12). Data as JSON: /api/errors/e73f442e9ca9ce03. Report an issue: GitHub.