{"record":{"id":"fd6d7658edce7bf9","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-room-fd6d76","errorCode":"error-invalid-room","errorMessage":"The rid field is invalid","messagePattern":"The rid field is invalid","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/rooms/invites/findOrCreateInvite.ts","lineNumber":52,"sourceCode":"\t\treturn false;\n\t}\n\n\tif (!invite.rid) {\n\t\tthrow new Meteor.Error('error-the-field-is-required', 'The field rid is required', {\n\t\t\tmethod: 'findOrCreateInvite',\n\t\t\tfield: 'rid',\n\t\t});\n\t}\n\n\tif (!(await hasPermissionAsync(userId, 'create-invite-links', invite.rid))) {\n\t\tthrow new Meteor.Error('not_authorized');\n\t}\n\n\tconst subscription = await Subscriptions.findOneByRoomIdAndUserId(invite.rid, userId, {\n\t\tprojection: { _id: 1 },\n\t});\n\tif (!subscription) {\n\t\tthrow new Meteor.Error('error-invalid-room', 'The rid field is invalid', {\n\t\t\tmethod: 'findOrCreateInvite',\n\t\t\tfield: 'rid',\n\t\t});\n\t}\n\n\tconst room = await Rooms.findOneById(invite.rid);\n\tif (!room) {\n\t\tthrow new Meteor.Error('error-invalid-room', 'The rid field is invalid', {\n\t\t\tmethod: 'findOrCreateInvite',\n\t\t\tfield: 'rid',\n\t\t});\n\t}\n\n\tif (settings.get('ABAC_Enabled') && room?.abacAttributes?.length) {\n\t\tthrow new Meteor.Error('error-invalid-room', 'Room is ABAC managed', {\n\t\t\tmethod: 'findOrCreateInvite',\n\t\t\tfield: 'rid',\n\t\t});","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/rooms/invites/findOrCreateInvite.ts#L34-L70","documentation":"After the permission check, findOrCreateInvite verifies the caller actually has a subscription in the target room and that the room document exists (Rooms.findOneById). Either failure throws error-invalid-room with message 'The rid field is invalid' and field rid, meaning the rid is well-formed but points to a room the user cannot invite into (no subscription) or that does not exist.","triggerScenarios":"Passing a rid for a room the user never joined (subscription lookup returns null), or a rid that matches no Rooms document — deleted room, id from another workspace, or a DM where the caller was removed. Both the subscription check (line 52) and the room-existence check (line 59) share this code.","commonSituations":"Invites created for archived rooms the user was removed from; workspace data migrated with new room ids while clients cached old ones; bot accounts creating invites without first joining the channel.","solutions":["Verify the caller has a subscription in the room (join the room) before creating invites","Confirm the room still exists with Rooms.findOneById(rid)","Use a fresh rid from the room document, not a cached id from another session or workspace"],"exampleFix":"// before\nawait findOrCreateInvite(userId, { rid, days, maxUses });\n\n// after\nconst sub = await Subscriptions.findOneByRoomIdAndUserId(rid, userId, { projections: { _id: 1 } });\nif (!sub) throw new Meteor.Error('error-invalid-room', 'Join the room before creating invites');\nawait findOrCreateInvite(userId, { rid, days, maxUses });","handlingStrategy":"validation","validationCode":"const [sub, room] = await Promise.all([\n  Subscriptions.findOneByRoomIdAndUserId(invite.rid, userId, { projections: { _id: 1 } }),\n  Rooms.findOneById(invite.rid, { projections: { _id: 1 } }),\n]);\nif (!sub || !room) {\n  throw new Meteor.Error('error-invalid-room', 'Join the room before creating an invite');\n}\nawait findOrCreateInvite(userId, invite);","typeGuard":null,"tryCatchPattern":"try {\n  await findOrCreateInvite(userId, invite);\n} catch (err) {\n  if (err instanceof Meteor.Error && err.error === 'error-invalid-room' && err.details?.field === 'rid') {\n    // user is not a member of the room or room is gone — prompt to join\n  }\n  throw err;\n}","preventionTips":["Have bots join channels before generating invite links","Clear cached rids after workspace migrations","Only offer invite creation inside rooms the user has joined"],"tags":["invite","room-not-found","subscription","validation"],"backgroundTag":"room-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}