RocketChat/Rocket.Chat · error · Meteor.Error
error-invalid-room
error-invalid-room
Error message
Invalid room
What it means
Thrown by the 'messages/get' Meteor method when rid is falsy after the check(rid, String) match — in practice an empty string. The room id is the primary key for the history query, so an empty value cannot resolve to a room. Non-string values are rejected earlier by check() with a Match failed error instead.
Source
Thrown at apps/meteor/server/publications/messages.ts:300
return handleCursorPagination(type, rid, count, next, previous);
};
Meteor.methods<ServerMethods>({
async 'messages/get'(
rid,
{ lastUpdate, latestDate = new Date(), oldestDate, inclusive = false, count = 20, unreads = false, next, previous, type },
) {
check(rid, String);
const fromId = Meteor.userId();
if (!fromId) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'messages/get' });
}
if (!rid) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'messages/get' });
}
return getMessageHistory(rid, fromId, { lastUpdate, latestDate, oldestDate, inclusive, count, unreads, next, previous, type });
},
});
View on GitHub (pinned to b2c16d5842)
Solutions
- Pass the room's _id (not its name) and verify it is non-empty before calling
- Derive rid from the user's subscription records when it is unknown
- Guard the call site: if (!rid) return
Example fix
// before
Meteor.call('messages/get', rid ?? '', { lastUpdate });
// after
if (!rid) throw new Error('rid is required');
Meteor.call('messages/get', rid, { lastUpdate }); Defensive patterns
Strategy: validation
Validate before calling
if (typeof rid !== 'string' || rid.trim() === '') {
throw new Error('a non-empty room id is required');
}
Meteor.call('messages/get', rid, params); Type guard
function isValidRoomId(rid: unknown): rid is string {
return typeof rid === 'string' && rid.length > 0;
} Try / catch
try { await Meteor.callAsync('messages/get', rid, params); } catch (e) { if (e.error === 'error-invalid-room') { /* resolve rid from subscriptions and retry */ } } Prevention
- Pass room _id, never the room name
- Derive rid from the subscription record when it is unknown
When it happens
Trigger: Meteor.call('messages/get', '', { ... }); calling with a rid variable that is undefined-but-defaulted to '' or comes from an unset route param.
Common situations: Route handlers that read :rid from a URL before the subscription populates; deserialized state where the room id was never stored; passing a room name instead of the _id.
Related errors
- error-message-same-as-tmid
- error-message-change-to-thread
- error-invalid-payload
- error-cursor-and-lastUpdate-conflict
- error-fromTs-requires-lastUpdate
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/550f11d06387a225.
Report an issue: GitHub.