{"record":{"id":"c191c7853604a4df","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-room-c191c7","errorCode":"error-invalid-room","errorMessage":"Invalid room","messagePattern":"Invalid room","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/rooms/settings/saveRoomName.ts","lineNumber":53,"sourceCode":"\t\tSubscriptions.updateNameAndAlertByRoomId(rid, slugifiedRoomName, displayName),\n\t]);\n\n\tif (responses[1]?.modifiedCount) {\n\t\tvoid notifyOnSubscriptionChangedByRoomId(rid);\n\t}\n\n\treturn responses;\n};\n\nexport async function saveRoomName(\n\trid: string,\n\tdisplayName: string | undefined,\n\tuser: IUser,\n\tsendMessage = true,\n): Promise<string | undefined> {\n\tconst room = await Rooms.findOneById(rid);\n\tif (!room) {\n\t\tthrow new Meteor.Error('error-invalid-room', 'Invalid room', {\n\t\t\tfunction: 'RocketChat.saveRoomdisplayName',\n\t\t});\n\t}\n\n\tif (roomCoordinator.getRoomDirectives(room.t).preventRenaming()) {\n\t\tthrow new Meteor.Error('error-not-allowed', 'Not allowed', {\n\t\t\tfunction: 'RocketChat.saveRoomdisplayName',\n\t\t});\n\t}\n\n\tawait Room.beforeNameChange(room);\n\n\tif (isRoomNativeFederated(room)) {\n\t\tdisplayName = `${displayName}:${room.federation.mrid.split(':').pop()}`;\n\t}\n\n\tif (displayName === room.name) {\n\t\treturn;","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/rooms/settings/saveRoomName.ts#L35-L71","documentation":"Thrown by saveRoomName when Rooms.findOneById(rid) returns null (saveRoomName.ts:53) — no room document exists for that id before any rename logic runs. Unlike the saveRoom* Match.test guards, this proves a string rid was given but resolves to nothing. Code 'error-invalid-room', details { function: 'RocketChat.saveRoomdisplayName' } (note the legacy typo in the function name).","triggerScenarios":"Renaming a room that was deleted between the client load and the save; rid typo/truncation; room exists only in another database/environment; archived-and-purged room still open in a stale UI tab.","commonSituations":"Two admins where one deletes the channel while the other edits settings; federation/replication lag; stale browser sessions hitting renamed/removed rooms.","solutions":["Verify the room exists: Rooms.findOneById(rid) before calling, and surface 'room not found' to the client","Reload the room list in the UI and retry against an existing room","Check for id truncation when rid travels through logs/queues","Confirm you are pointed at the right database/environment"],"exampleFix":"// before\nawait saveRoomName(rid, displayName, user);\n\n// after\nconst room = await Rooms.findOneById(rid);\nif (!room) {\n\tthrow new Meteor.Error('error-invalid-room', 'Room not found — it may have been deleted');\n}\nawait saveRoomName(rid, displayName, user);","handlingStrategy":"validation","validationCode":"const room = await Rooms.findOneById(rid);\nif (!room) {\n\tthrow new Meteor.Error('error-invalid-room', 'Room not found — it may have been deleted');\n}\nawait saveRoomName(rid, displayName, user);","typeGuard":null,"tryCatchPattern":"try {\n\tawait saveRoomName(rid, displayName, user);\n} catch (e) {\n\tif (e instanceof Meteor.Error && e.error === 'error-invalid-room') {\n\t\t// room vanished: refresh the client's room list instead of retrying\n\t}\n}","preventionTips":["Re-verify the room exists on save rather than trusting a stale form state","Handle deleted-room errors by refreshing UI state, not by retrying the same rid","Guard rid integrity when it passes through queues/logs (no truncation)"],"tags":["room","rename","not-found","stale-state"],"backgroundTag":"room-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}