RocketChat/Rocket.Chat · warning · Meteor.Error

error-no-messages

error-no-messages

Error message

No messages found

What it means

After Messages.findPaginated, dmMessagesOthersAction awaits [msgs, total] and throws error-no-messages when !msgs. In practice this branch is effectively dead code: cursor.toArray() always resolves to an array (possibly empty), which is truthy, so the guard never trips. An empty result instead returns count:0 with an empty messages array. Treat any observed occurrence as a driver/cursor anomaly rather than an empty-room condition.

Source

Thrown at apps/meteor/server/api/v1/im.ts:821

		if (!room || room?.t !== 'd') {
			throw new Meteor.Error('error-room-not-found', `No direct message room found by the id of: ${roomId}`);
		}

		const { offset, count } = await getPaginationItems(this.queryParams);
		const { sort, fields, query } = await this.parseJsonQuery();
		const ourQuery = Object.assign({}, query, { rid: room._id });

		const { cursor, totalCount } = Messages.findPaginated<IMessage>(ourQuery, {
			sort: sort || { ts: -1 },
			skip: offset,
			limit: count,
			projection: fields,
		});

		const [msgs, total] = await Promise.all([cursor.toArray(), totalCount]);

		if (!msgs) {
			throw new Meteor.Error('error-no-messages', 'No messages found');
		}

		return API.v1.success({
			messages: await normalizeMessagesForUser(msgs, this.userId),
			offset,
			count: msgs.length,
			total,
		});
	};

const dmListEndpointsProps = {
	authRequired: true as const,
	response: {
		200: paginatedImsResponseSchema,
		400: validateBadRequestErrorResponse,
		401: validateUnauthorizedErrorResponse,
	},
};

View on GitHub (pinned to f9d3ec372b)

Solutions

  1. Do not try to 'fix' empty rooms here — an empty result returns 200 with count 0.
  2. If genuinely hit, inspect the Messages cursor/driver in use.
  3. Report as a likely dead-code path; the intent was probably `if (!msgs.length)`.

Example fix

// current (effectively unreachable)
if (!msgs) { throw new Meteor.Error('error-no-messages', 'No messages found'); }

// probable intent
if (!msgs.length) { return API.v1.success({ messages: [], offset, count: 0, total }); }
Defensive patterns

Strategy: try-catch

Validate before calling

// No caller-side prevention needed: empty results return 200 with count 0.
// If you truly see error-no-messages, log the driver/cursor state for investigation.
const log = (msg) => console.warn('[im.messages.others]', msg);

Try / catch

try {
  const r = await api.get('/api/v1/im.messages.others', { params: { roomId } });
  // empty is normal: r.data.count === 0
} catch (e) {
  if (e.response?.data?.error === 'error-no-messages') {
    // unexpected — treat as success with empty list and report upstream
  } else throw e;
}

Prevention

When it happens

Trigger: Effectively unreachable under normal MongoDB driver behavior — would require cursor.toArray() to resolve to null/undefined. Empty message sets do NOT trigger this; they return success with count 0.

Common situations: Should not occur in practice. If reported, suspect a mocked/custom cursor, an exotic driver version, or a misattributed error code.

Related errors


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