{"record":{"id":"47f9c1e009eb0e4c","repo":"RocketChat/Rocket.Chat","slug":"team-does-not-exist","errorCode":null,"errorMessage":"team-does-not-exist","messagePattern":"team-does-not-exist","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/services/team/service.ts","lineNumber":713,"sourceCode":"\t\t}\n\n\t\treturn {\n\t\t\ttotal: await totalCount,\n\t\t\trecords: results,\n\t\t};\n\t}\n\n\tasync addMembers(uid: string, teamId: string, members: Array<ITeamMemberParams>): Promise<void> {\n\t\tconst createdBy = (await Users.findOneById(uid, { projection: { username: 1 } })) as Pick<IUser, '_id' | 'username'>;\n\t\tif (!createdBy) {\n\t\t\tthrow new Error('invalid-user');\n\t\t}\n\n\t\tconst team = await Team.findOneById<Pick<ITeam, 'roomId'>>(teamId, {\n\t\t\tprojection: { roomId: 1 },\n\t\t});\n\t\tif (!team) {\n\t\t\tthrow new Error('team-does-not-exist');\n\t\t}\n\n\t\tfor await (const member of members) {\n\t\t\tconst user = (await Users.findOneById(member.userId, { projection: { username: 1 } })) as Pick<IUser, '_id' | 'username'>;\n\t\t\tawait addUserToRoom(team.roomId, user, createdBy, { skipSystemMessage: false });\n\n\t\t\tif (member.roles) {\n\t\t\t\tconst isRoleAddedToTeam = await this.addRolesToMember(teamId, member.userId, member.roles);\n\t\t\t\tconst isRoleAddedToSubscription = await this.addRolesToSubscription(team.roomId, member.userId, member.roles);\n\t\t\t\tif (settings.get<boolean>('UI_DisplayRoles') && isRoleAddedToTeam && isRoleAddedToSubscription) {\n\t\t\t\t\tmember.roles.forEach((role) => {\n\t\t\t\t\t\tvoid api.broadcast('user.roleUpdate', {\n\t\t\t\t\t\t\ttype: 'added',\n\t\t\t\t\t\t\t_id: role,\n\t\t\t\t\t\t\tu: {\n\t\t\t\t\t\t\t\t_id: user._id,\n\t\t\t\t\t\t\t\tusername: user.username,\n\t\t\t\t\t\t\t},","sourceCodeStart":695,"sourceCodeEnd":731,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/services/team/service.ts#L695-L731","documentation":"Thrown by TeamService.addMembers (apps/meteor/server/services/team/service.ts:713) when Team.findOneById(teamId, { projection: { roomId: 1 } }) returns null — no team with that ID. The roomId projection is needed because members are added by joining the team's main channel via addUserToRoom. Over REST, teams.addMembers resolves the team first and returns its own 'team-does-not-exist' failure, so seeing the service's throw means a direct call or a delete race.","triggerScenarios":"Direct Team.addMembers(uid, staleTeamId, members); team deleted between the endpoint's getTeamByIdOrName resolution and the service lookup; mistyped IDs; teams on another workspace.","commonSituations":"Bulk member-sync jobs running while teams are being reorganized; UI holding a stale team reference after deletion; captured request replay against a different database.","solutions":["Re-resolve the team immediately before adding members and abort on null","In long-running sync jobs, catch this error per-team and log/skip rather than aborting the whole run","Over REST, rely on the endpoint's team-does-not-exist response and refresh the team list in the client"],"exampleFix":"// before\nawait Team.addMembers(uid, staleTeamId, members); // throws team-does-not-exist\n\n// after\nconst team = await Team.findOneById(teamId, { projection: { roomId: 1 } });\nif (!team) {\n\tthrow new Error('team-does-not-exist');\n}\nawait Team.addMembers(uid, team._id, members);","handlingStrategy":"try-catch","validationCode":"const team = await Team.findOneById(teamId, { projection: { roomId: 1 } });\nif (!team) {\n\tthrow new Error('team-does-not-exist');\n}\nawait Team.addMembers(uid, team._id, members);","typeGuard":null,"tryCatchPattern":"try {\n\tawait Team.addMembers(uid, teamId, members);\n} catch (e) {\n\tif (e instanceof Error && e.message === 'team-does-not-exist') {\n\t\t// team removed mid-sync — skip this batch entry\n\t}\n\tthrow e;\n}","preventionTips":["In member-sync jobs, resolve the team per iteration and tolerate deletion","Refresh team references in UIs after team-management operations","Log teamId alongside the error to spot environment-mismatched IDs quickly"],"tags":["rocket-chat","teams","not-found","server-side"],"backgroundTag":"team-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}