RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-dates

error-invalid-dates

Error message

From date cannot be after To date

What it means

Thrown by POST /api/v1/rooms.export with type 'file' when convertedDateFrom is greater than convertedDateTo. dateFrom defaults to epoch 0 and dateTo defaults to now, and the server adds one day to dateTo before comparing, so the error only fires when the caller explicitly sends an inverted or overlapping range.

Solutions

  1. Validate and swap/reject the range client-side before sending
  2. Check the field wiring: dateFrom is the older bound, dateTo the newer
  3. Rely on defaults (omit both) when exporting the full history

Example fix

// before
await sdk.post('rooms.export', { rid, type: 'file', dateFrom: '2026-08-18', dateTo: '2026-08-01' }); // inverted

// after
let [from, to] = [new Date(dateFrom), new Date(dateTo)].sort((a, b) => a - b);
await sdk.post('rooms.export', { rid, type: 'file', dateFrom: from.toISOString(), dateTo: to.toISOString() });
Defensive patterns

Strategy: validation

Validate before calling

const from = new Date(dateFrom ?? 0);
const to = new Date(dateTo ?? Date.now());
if (from > to) [dateFrom, dateTo] = [dateTo, dateFrom]; // or reject with a form error

Try / catch

try {
  await sdk.post('rooms.export', { rid, type: 'file', dateFrom, dateTo });
} catch (e: any) {
  if (e?.response?.data?.errorType === 'error-invalid-dates') {
    throw new Error('export range inverted — fix dateFrom/dateTo order');
  }
  throw e;
}

Prevention

When it happens

Trigger: POST rooms.export with dateFrom later than dateTo (e.g. from 2026-08-18, to 2026-08-01); date pickers submitting end-before-start; timezone conversion flipping the order across midnight.

Common situations: UIs with two independent date inputs and no ordering validation; reports where 'from' and 'to' fields are wired in reverse; DST or timezone shifts reordering same-day ranges; copy-pasted ranges from other tools.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@e4b8178b20 (2026-08-18). Data as JSON: /api/errors/9a161907e4fd3b30. Report an issue: GitHub.

Appendix: source

Thrown at apps/meteor/server/api/v1/rooms.ts:1039

			throw new Meteor.Error('error-invalid-room');
		}

		const user = await Users.findOneById(this.userId);

		if (!user || !(await canAccessRoomAsync(room, user))) {
			throw new Meteor.Error('error-not-allowed', 'Not Allowed');
		}

		if (type === 'file') {
			const { dateFrom, dateTo } = this.bodyParams;
			const { format } = this.bodyParams;

			const convertedDateFrom = dateFrom ? new Date(dateFrom) : new Date(0);
			const convertedDateTo = dateTo ? new Date(dateTo) : new Date();
			convertedDateTo.setDate(convertedDateTo.getDate() + 1);

			if (convertedDateFrom > convertedDateTo) {
				throw new Meteor.Error('error-invalid-dates', 'From date cannot be after To date');
			}

			void dataExport.sendFile(
				{
					rid,
					format,
					dateFrom: convertedDateFrom,
					dateTo: convertedDateTo,
				},
				user,
			);
			return API.v1.success();
		}

		if (type === 'email') {
			const { toUsers, toEmails, subject, messages } = this.bodyParams;

			if ((!toUsers || toUsers.length === 0) && (!toEmails || toEmails.length === 0)) {

View on GitHub (pinned to e4b8178b20)