{"record":{"id":"9acabf4136f5a145","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-room-9acabf","errorCode":"error-invalid-room","errorMessage":"Invalid room","messagePattern":"Invalid room","errorType":"error_code","errorClass":"MeteorError","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/hooks/federation/index.ts","lineNumber":46,"sourceCode":"\t}\n\n\tconst federatedRoomId = room?.federation?.mrid;\n\tif (!federatedRoomId) {\n\t\tawait FederationMatrix.createRoom(room, owner);\n\t} else {\n\t\t// TODO unify how to get server\n\t\t// matrix room was already created and passed\n\t\tconst fromServer = federatedRoomId.split(':')[1];\n\n\t\tawait Rooms.setAsFederated(room._id, {\n\t\t\tmrid: federatedRoomId,\n\t\t\torigin: fromServer,\n\t\t});\n\t}\n\n\tconst federationRoom = await Rooms.findOneById(room._id);\n\tif (!federationRoom || !isRoomNativeFederated(federationRoom)) {\n\t\tthrow new MeteorError('error-invalid-room', 'Invalid room');\n\t}\n\n\t// TODO this won't be neeeded once we receive all state events at ee/packages/federation-matrix/src/events/member.ts\n\tawait FederationMatrix.inviteUsersToRoom(\n\t\tfederationRoom,\n\t\tmembers.filter((member) => member !== owner.username),\n\t\towner,\n\t);\n});\n\ncallbacks.add(\n\t'afterSaveMessage',\n\tasync (message, { room, user }) => {\n\t\tif (!FederationActions.shouldPerformFederationAction(room)) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/ee/server/hooks/federation/index.ts#L28-L64","documentation":"Thrown by the federation `afterCreateRoom`-style hook when, after marking a room as federated, the room cannot be re-fetched from the DB OR the fetched room fails `isRoomNativeFederated()`. It is a `MeteorError` with code `error-invalid-room`. The check guards the subsequent Matrix invite call so it never runs against a non-federated room record.","triggerScenarios":"Inside the federation room-creation hook: `Rooms.findOneById(room._id)` returns null, or the returned room is not native-federated (missing/invalid `federation` field) after the `setAsFederated` step.","commonSituations":"Race condition where the room was deleted between creation and re-fetch; `setAsFederated` failed silently or the federation data shape changed; a non-federated room erroneously entered the federation hook path due to a routing bug.","solutions":["Verify the room still exists and its `federation` field is populated before the hook runs.","Check `setAsFederated` succeeded (no write errors) and the mrid/origin were stored.","Confirm `isRoomNativeFederated()` criteria match the room record shape in the current version."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { isRoomNativeFederated } from '@rocket.chat/core-typings';\nimport { Rooms } from '../../../../server/models';\n\nasync function roomIsFederatedAndValid(roomId: string): Promise<boolean> {\n\tconst room = await Rooms.findOneById(roomId);\n\treturn Boolean(room && isRoomNativeFederated(room));\n}","typeGuard":"function isInvalidFederatedRoomError(e: unknown): boolean {\n\treturn e instanceof Meteor.Error && (e as Meteor.Error).error === 'error-invalid-room';\n}","tryCatchPattern":"try {\n\tawait callbacks.run('afterCreateRoom', room, members, owner);\n} catch (e) {\n\tif (e instanceof Meteor.Error && e.error === 'error-invalid-room') {\n\t\t// room not federated after setAsFederated — investigate DB write\n\t}\n\tthrow e;\n}","preventionTips":["Verify the room record and its `federation` field before triggering federation hooks.","Ensure `setAsFederated` writes succeed before downstream Matrix calls.","Guard against room deletion races in concurrent flows."],"tags":["federation","rooms","ee","meteor-error"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}