{"record":{"id":"2eb71072e2cef7d8","repo":"RocketChat/Rocket.Chat","slug":"one-or-more-of-the-users-have-been-assigned-invali","errorCode":null,"errorMessage":"One or more of the users have been assigned invalid roles.","messagePattern":"One or more of the users have been assigned invalid roles\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/services/import/service.ts","lineNumber":136,"sourceCode":"\n\t\tthis.assertsValidStateForNewData(operation);\n\n\t\tconst defaultRoles = getNewUserRoles();\n\t\tconst userRoles = new Set<string>(defaultRoles);\n\t\tfor await (const user of users) {\n\t\t\tif (!user.emails?.some((value) => value) || !user.importIds?.some((value) => value)) {\n\t\t\t\tthrow new Error('Users are missing required data.');\n\t\t\t}\n\n\t\t\tif (user.roles?.length) {\n\t\t\t\tfor (const roleId of user.roles) {\n\t\t\t\t\tuserRoles.add(roleId);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (userRoles.size > 0 && !(await validateRoleList([...userRoles]))) {\n\t\t\tthrow new Error('One or more of the users have been assigned invalid roles.');\n\t\t}\n\n\t\tawait ImportData.col.insertMany(\n\t\t\tusers.map((data) => ({\n\t\t\t\t_id: new ObjectId().toHexString(),\n\t\t\t\tdata: {\n\t\t\t\t\t...data,\n\t\t\t\t\troles: data.roles ? [...new Set([...data.roles, ...defaultRoles])] : defaultRoles,\n\t\t\t\t},\n\t\t\t\tdataType: 'user',\n\t\t\t\t_updatedAt: new Date(),\n\t\t\t})),\n\t\t);\n\n\t\tawait Imports.increaseTotalCount(operation._id, 'users', users.length);\n\t\tawait Imports.setOperationStatus(operation._id, 'importer_user_selection');\n\t}\n","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/services/import/service.ts#L118-L154","documentation":"Thrown by addUsers when validateRoleList() rejects one or more roles referenced by the imported users (including default roles). Before inserting, the service collects the union of all user roles and validates them against the workspace's existing roles; any unknown role id/name fails the whole batch.","triggerScenarios":"Importing users whose roles exist in the source workspace but not in the target; role renames between workspaces; scoped/EE roles missing on a Community target; default role list corrupted.","commonSituations":"Cross-workspace migrations without role pre-creation; imports from systems with custom role models; fresh installs that never created the custom roles used by the source.","solutions":["Create the missing roles on the target workspace before importing","Map source role names to existing target roles in the importer configuration","Strip unknown roles from user records when they are not needed"],"exampleFix":"// before\nawait service.addUsers(usersWithSourceRoles);\n\n// after\nconst known = new Set(await Roles.find({}, { fields: { _id: 1 } }).map((r) => r._id));\nconst sanitized = users.map((u) => ({ ...u, roles: u.roles?.filter((r) => known.has(r)) }));\nawait service.addUsers(sanitized);","handlingStrategy":"validation","validationCode":"const roles = [...new Set(users.flatMap((u) => u.roles ?? []))];\nif (roles.length && !(await validateRoleList(roles))) {\n  throw new Error(`unknown roles: ${roles.join(', ')}`);\n}\nawait service.addUsers(users);","typeGuard":"async function allRolesExist(roles: string[]): Promise<boolean> {\n  const known = new Set((await Roles.find({}, { fields: { _id: 1 } }).fetch()).map((r) => r._id));\n  return roles.every((r) => known.has(r));\n}","tryCatchPattern":null,"preventionTips":["Pre-create or map custom roles on the target workspace before import","Include role validation in dry-run import checks"],"tags":["import","roles","validation","rocket-chat"],"backgroundTag":"unknown-role-reference","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"}