{"record":{"id":"ab7d2e5ba8259c99","repo":"RocketChat/Rocket.Chat","slug":"error-user-not-leader","errorCode":"error-user-not-leader","errorMessage":"User is not a leader","messagePattern":"User is not a leader","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/rooms/removeRoomLeader.ts","lineNumber":48,"sourceCode":"\n\tconst user = await Users.findOneById(userId);\n\n\tif (!user?.username) {\n\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\tmethod: 'removeRoomLeader',\n\t\t});\n\t}\n\n\tconst subscription = await Subscriptions.findOneByRoomIdAndUserId(rid, user._id);\n\n\tif (!subscription) {\n\t\tthrow new Meteor.Error('error-user-not-in-room', 'User is not in this room', {\n\t\t\tmethod: 'removeRoomLeader',\n\t\t});\n\t}\n\n\tif (subscription.roles && Array.isArray(subscription.roles) === true && subscription.roles.includes('leader') === false) {\n\t\tthrow new Meteor.Error('error-user-not-leader', 'User is not a leader', {\n\t\t\tmethod: 'removeRoomLeader',\n\t\t});\n\t}\n\n\tconst removeRoleResponse = await Subscriptions.removeRoleById(subscription._id, 'leader');\n\tawait syncRoomRolePriorityForUserAndRoom(userId, rid, subscription.roles?.filter((r) => r !== 'leader') || []);\n\n\tif (removeRoleResponse.modifiedCount) {\n\t\tvoid notifyOnSubscriptionChangedById(subscription._id);\n\t}\n\n\tconst fromUser = await Users.findOneById(fromUserId);\n\tif (!fromUser) {\n\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\tmethod: 'removeRoomLeader',\n\t\t});\n\t}\n","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/rooms/removeRoomLeader.ts#L30-L66","documentation":"Error \"User is not a leader\" thrown in RocketChat/Rocket.Chat.","triggerScenarios":"Thrown by `removeRoomLeader` (removeRoomLeader.ts:48) when the target user's subscription has a roles array that does not include 'leader', i.e. the user is a room member but does not currently hold the leader role.","commonSituations":"Leader role was already removed; user was never a leader; concurrent role changes.","solutions":["Check the subscription's roles array includes 'leader' before calling removeRoomLeader; skip the call otherwise.","Refresh the room's leader list in the UI after any role change to avoid acting on stale data."],"exampleFix":"const sub = await Subscriptions.findOneByRoomIdAndUserId(rid, userId);\nif (sub?.roles?.includes('leader')) {\n  await Meteor.callAsync('removeRoomLeader', rid, userId);\n}","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}