{"record":{"id":"61308e13eab24d92","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-61308e","errorCode":"error-invalid-user","errorMessage":"Invalid user","messagePattern":"Invalid user","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/rooms/createRoom.ts","lineNumber":211,"sourceCode":"\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) {\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 (!excludeSelf && owner.username && !memberList.includes(owner.username)) {\n\t\tmemberList.push(owner.username);\n\t}\n\n\tif (extraData.broadcast) {\n\t\treadOnly = true;\n\t\tdelete extraData.reactWhenReadOnly;\n\t}","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/rooms/createRoom.ts#L193-L229","documentation":"createRoom throws error-invalid-user (with function RocketChat.createRoom) when the owner argument is falsy — no user document/object was supplied as the room creator. The owner drives subscription creation and must exist.","triggerScenarios":"Calling createRoom with owner = null/undefined — typically because a Users.findOneByUsername lookup earlier in the call chain returned null (user not found) and was passed through unchecked.","commonSituations":"Creating rooms on behalf of a username that does not exist (typo, deleted user, or bot user not yet provisioned); importers or scripts that resolve the owner by username and skip the null check.","solutions":["Verify the owner exists before creating the room: const owner = await Users.findOneByUsername(username); if (!owner) throw ...","If the user was deleted, restore it or pick another owner","Log the resolved owner id/username right before createRoom in your integration to catch pass-through nulls"],"exampleFix":"// before\ncreateRoom('c', name, await Users.findOneByUsername(username), members, extraData);\n\n// after\nconst owner = await Users.findOneByUsername(username);\nif (!owner) throw new Meteor.Error('error-invalid-user', `Owner ${username} not found`);\ncreateRoom('c', name, owner, members, extraData);","handlingStrategy":"type-guard","validationCode":"const owner = await Users.findOneByUsername(ownerUsername);\nif (!owner) {\n  throw new Meteor.Error('error-invalid-user', `Owner ${ownerUsername} not found`);\n}\nawait createRoom(type, name, owner, members, extraData);","typeGuard":"const isExistingOwner = (owner: unknown): owner is IUser =>\n  Boolean(owner && typeof owner === 'object' && '_id' in owner);","tryCatchPattern":"try {\n  await createRoom(type, name, owner, members, extraData);\n} catch (err) {\n  if (err instanceof Meteor.Error && err.error === 'error-invalid-user') {\n    // re-resolve the owner by username, verify existence, then retry\n  }\n  throw err;\n}","preventionTips":["Always null-check the owner lookup in the same expression where it is fetched","Validate bot/service accounts exist before scheduling room creation jobs","Log owner resolution failures with the username for quick diagnosis"],"tags":["room-creation","validation","owner","user-not-found"],"backgroundTag":"user-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}