{"record":{"id":"517e0346c25062d5","repo":"RocketChat/Rocket.Chat","slug":"user-not-found-517e03","errorCode":null,"errorMessage":"User not found","messagePattern":"User not found","errorType":"exception","errorClass":null,"httpStatus":400,"severity":"error","filePath":"apps/meteor/server/lib/banUserFromRoom.ts","lineNumber":33,"sourceCode":"\n\tconst room = await Rooms.findOneById(data.rid);\n\n\tif (!room || !(await roomCoordinator.getRoomDirectives(room.t).allowMemberAction(room, RoomMemberActions.BAN, fromId))) {\n\t\tthrow new Error('Not allowed');\n\t}\n\n\tconst fromUser = await Users.findOneById(fromId);\n\tif (!fromUser) {\n\t\tthrow new Error('Invalid user');\n\t}\n\n\tif (!(await canAccessRoomAsync(room, fromUser))) {\n\t\tthrow new Error('The required \"roomId\" or \"roomName\" param provided does not match any group');\n\t}\n\n\tconst bannedUser = await Users.findOneByUsernameIgnoringCase(data.username);\n\tif (!bannedUser) {\n\t\tthrow new Error('User not found');\n\t}\n\n\tconst subscription = await Subscriptions.findOneByRoomIdAndUserId(data.rid, bannedUser._id, {\n\t\tprojection: { _id: 1, status: 1 },\n\t});\n\tif (!subscription) {\n\t\tthrow new Error('User is not in this room');\n\t}\n\n\t// Cannot ban a user who is already banned\n\tif (isBannedSubscription(subscription)) {\n\t\tthrow new Error('User is already banned from this room');\n\t}\n\n\t// Cannot ban the last owner\n\tif (await hasRoleAsync(bannedUser._id, 'owner', room._id)) {\n\t\tconst numOwners = await Roles.countUsersInRole('owner', room._id);\n","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/banUserFromRoom.ts#L15-L51","documentation":"Users.findOneByUsernameIgnoringCase(data.username) found no user, so the ban target does not exist. Username (not user id or display name) is the lookup key and must match a current username case-insensitively.","triggerScenarios":"Typo in the username payload; the target renamed their username; a deleted or deactivated user; passing the display name or user id where username is expected.","commonSituations":"Hand-typed /ban slash commands; bots guessing usernames; UIs submitting stale usernames from an old member list.","solutions":["Resolve the user first (users.info?username=...) and submit the canonical username","Offer username autocomplete instead of free-text entry","Handle 'User not found' distinctly from 'Not allowed' in the UI"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const { user } = await GET '/api/v1/users.info' { username };\nif (!user) {\n  // no such username - do not call rooms.banUser\n}","typeGuard":null,"tryCatchPattern":"try {\n  await POST '/api/v1/rooms.banUser' { roomId, username };\n} catch (e) {\n  if (String(e.message).includes('User not found')) {\n    // resolve canonical username via users.info and retry once\n  } else {\n    throw e;\n  }\n}","preventionTips":["Use username autocomplete instead of free-text ban targets","Submit the canonical username (not display name or user id)","Refresh user data before acting on old member lists"],"tags":["rocket-chat","users","moderation","username-lookup"],"backgroundTag":"user-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}