{"record":{"id":"798f8dce80004d30","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-members","errorCode":"error-invalid-members","errorMessage":"members should be an array of usernames if provided for rooms other than direct messages","messagePattern":"members should be an array of usernames if provided for rooms other than direct messages","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/rooms/createRoom.ts","lineNumber":198,"sourceCode":"\t\t// options,\n\t});\n\n\tconst shouldBeHandledByFederation = extraData.federated === true;\n\n\tif (shouldBeHandledByFederation && owner && !isUserNativeFederated(owner) && !(await FederationMatrix.canUserAccessFederation(owner))) {\n\t\tthrow new Meteor.Error('error-not-authorized-federation', 'Not authorized to access federation', {\n\t\t\tmethod: 'createRoom',\n\t\t});\n\t}\n\n\tif (type === 'd') {\n\t\treturn createDirectRoom(members as IUser[], extraData, { ...options, creator: options?.creator || owner?._id });\n\t}\n\n\tconst memberList = [...members];\n\n\tif (!onlyUsernames(memberList)) {\n\t\tthrow new Meteor.Error(\n\t\t\t'error-invalid-members',\n\t\t\t'members should be an array of usernames if provided for rooms other than direct messages',\n\t\t);\n\t}\n\n\tif (!isValidName(name)) {\n\t\tthrow new Meteor.Error('error-invalid-name', 'Invalid name', {\n\t\t\tfunction: 'RocketChat.createRoom',\n\t\t});\n\t}\n\n\tif (!owner) {\n\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\tfunction: 'RocketChat.createRoom',\n\t\t});\n\t}\n\n\tif (!owner?.username) {","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/rooms/createRoom.ts#L180-L216","documentation":"For every room type except direct messages ('d'), createRoom requires members to be an array of plain username strings. The onlyUsernames type guard fails if any element is a user object, null, or a non-string, producing error-invalid-members.","triggerScenarios":"Calling createRoom with type 'c'/'p'/'l'/'t' and members containing objects (e.g. full IUser documents from a find() call), numbers, or undefined entries. Direct rooms ('d') bypass this and accept IUser[] because they are routed to createDirectRoom before the check.","commonSituations":"Reusing a members array fetched from the database (user documents) instead of mapping to usernames; mixing APIs — passing the same payload to createDirectMessage and createRoom; forgetting .map(u => u.username) after a Users query.","solutions":["Map members to username strings before calling createRoom for non-DM rooms: members.map(u => typeof u === 'string' ? u : u.username)","Use a dedicated typed helper or the REST API schema so members must be string[]","If you really intended object members for a DM, ensure type is 'd'"],"exampleFix":"// before\ncreateRoom('c', name, owner, usersFromDb, extraData);\n\n// after\ncreateRoom('c', name, owner, usersFromDb.map(u => u.username), extraData);","handlingStrategy":"type-guard","validationCode":"const memberNames = members.map(m => (typeof m === 'string' ? m : m?.username)).filter(Boolean) as string[];\nif (type !== 'd' && members.some(m => typeof m !== 'string')) {\n  // normalized above; safe to proceed\n}\nawait createRoom(type, name, owner, memberNames, extraData);","typeGuard":"const onlyUsernames = (members: unknown): members is string[] =>\n  Array.isArray(members) && members.every(m => typeof m === 'string');","tryCatchPattern":"try {\n  await createRoom(type, name, owner, members, extraData);\n} catch (err) {\n  if (err instanceof Meteor.Error && err.error === 'error-invalid-members') {\n    // normalize members to usernames and retry\n  }\n  throw err;\n}","preventionTips":["Type the members parameter as string[] for non-DM rooms at the call site","Map DB user documents to usernames immediately after every query","Share one normalization helper across all room-creation call sites"],"tags":["room-creation","validation","members","typescript"],"backgroundTag":"schema-validation-failed","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}