{"record":{"id":"322bf497b33d9812","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-room-322bf4","errorCode":"error-invalid-room","errorMessage":"Invalid room","messagePattern":"Invalid room","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/messages/loadNextMessages.ts","lineNumber":29,"sourceCode":"\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {\n\t\tloadNextMessages(rid: IRoom['_id'], end?: Date, limit?: number): Promise<{ messages: IMessage[] }>;\n\t}\n}\n\nMeteor.methods<ServerMethods>({\n\tasync loadNextMessages(rid, end, limit = 20) {\n\t\tcheck(rid, String);\n\t\tcheck(limit, Number);\n\n\t\tif (!Meteor.userId()) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\t\tmethod: 'loadNextMessages',\n\t\t\t});\n\t\t}\n\n\t\tif (!rid) {\n\t\t\tthrow new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'loadNextMessages' });\n\t\t}\n\n\t\tconst fromId = Meteor.userId();\n\n\t\tif (!fromId || !(await canAccessRoomIdAsync(rid, fromId))) {\n\t\t\tthrow new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'loadNextMessages' });\n\t\t}\n\n\t\tlet records;\n\t\tif (end) {\n\t\t\trecords = await Messages.findVisibleByRoomIdAfterTimestamp(rid, end, true, {\n\t\t\t\tsort: {\n\t\t\t\t\tts: 1,\n\t\t\t\t},\n\t\t\t\tlimit,\n\t\t\t}).toArray();\n\t\t} else {\n\t\t\trecords = await Messages.findVisibleByRoomId(rid, {","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/messages/loadNextMessages.ts#L11-L47","documentation":"loadNextMessages throws error-invalid-room when rid is falsy. check(rid, String) already guaranteed the type, so this branch is reachable only with the empty string '' — any null/undefined/non-string would have failed check() with a Match error before reaching this line.","triggerScenarios":"Meteor.call('loadNextMessages', '', end, limit) — rid read from an unset state field, an empty URL parameter, or a room subscription that has not delivered the record yet.","commonSituations":"Component renders before the room data arrives and passes an empty id; refactors that leave an intermediate variable uninitialized; optional route params used without a default.","solutions":["Guard rid (non-empty string) before calling","Initialize rid from the room record/subscription and render loading state until it exists","Fail fast in development when rid is missing to catch state bugs"],"exampleFix":"// before\nconst { messages } = await Meteor.callAsync('loadNextMessages', rid, end, limit);\n\n// after\nif (typeof rid !== 'string' || rid.length === 0) {\n  return { messages: [] }; // or await room load\n}\nconst { messages } = await Meteor.callAsync('loadNextMessages', rid, end, limit);","handlingStrategy":"validation","validationCode":"if (typeof rid !== 'string' || rid.length === 0) {\n  return { messages: [] }; // room id not ready yet\n}","typeGuard":"const isNonEmptyRoomId = (rid: unknown): rid is string =>\n  typeof rid === 'string' && rid.trim().length > 0;","tryCatchPattern":null,"preventionTips":["Render a loading state until the room record supplies a real rid","Validate optional route params before using them in method calls","Note that null/undefined rid fails check() as Match failed; only '' reaches this error"],"tags":["validation","room-id","meteor-method"],"backgroundTag":"invalid-room-id","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}