{"record":{"id":"dd00120b27003b49","repo":"RocketChat/Rocket.Chat","slug":"error-the-field-is-required-dd0012","errorCode":"error-the-field-is-required","errorMessage":"The field rid is required","messagePattern":"The field rid is required","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/rooms/invites/findOrCreateInvite.ts","lineNumber":38,"sourceCode":"\t\t{\n\t\t\tfull: useDirectLink,\n\t\t\tcloud: !useDirectLink,\n\t\t\tcloud_route: 'invite',\n\t\t},\n\t\tsettings.get<string>('DeepLink_Url'),\n\t);\n}\n\nconst possibleDays = [0, 1, 7, 15, 30];\nconst possibleUses = [0, 1, 5, 10, 25, 50, 100];\n\nexport const findOrCreateInvite = async (userId: string, invite: Pick<IInvite, 'rid' | 'days' | 'maxUses'>) => {\n\tif (!userId || !invite) {\n\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}","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/rooms/invites/findOrCreateInvite.ts#L20-L56","documentation":"findOrCreateInvite validates that the invite payload contains a rid (room id) before doing anything else; a missing/empty invite.rid throws error-the-field-is-required with method findOrCreateInvite and field rid attached for field-level error mapping.","triggerScenarios":"Calling findOrCreateInvite(userId, { days, maxUses }) with rid undefined/'' — typically the caller resolved the room earlier, got null, and spread the result into the invite object anyway.","commonSituations":"REST/method handlers passing through client payloads that omitted rid; UI forms where the room selector failed silently and submitted anyway; refactors that renamed the field (roomId vs rid).","solutions":["Ensure the invite payload includes rid before calling findOrCreateInvite","Resolve the room once and use its id: { rid: room._id, days, maxUses }","Validate the payload against the REST/method schema at the boundary"],"exampleFix":"// before\nawait findOrCreateInvite(userId, { days, maxUses });\n\n// after\nif (!invite.rid) {\n  throw new Meteor.Error('error-the-field-is-required', 'The field rid is required');\n}\nawait findOrCreateInvite(userId, invite);","handlingStrategy":"validation","validationCode":"if (!invite?.rid) {\n  throw new Meteor.Error('error-the-field-is-required', 'The field rid is required', { field: 'rid' });\n}\nawait findOrCreateInvite(userId, invite);","typeGuard":"const hasRid = (invite: Pick<IInvite, 'rid' | 'days' | 'maxUses'> | undefined): invite is Pick<IInvite, 'rid' | 'days' | 'maxUses'> & { rid: string } =>\n  Boolean(invite && invite.rid);","tryCatchPattern":"try {\n  await findOrCreateInvite(userId, invite);\n} catch (err) {\n  if (err instanceof Meteor.Error && err.error === 'error-the-field-is-required' && err.details?.field === 'rid') {\n    // fix the payload — room selector failed upstream\n  }\n  throw err;\n}","preventionTips":["Validate required invite fields in the form/UI before submission","Type the invite payload with required rid at the boundary","Map err.details.field to per-field form errors"],"tags":["invite","validation","required-field","room-id"],"backgroundTag":"schema-validation-failed","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}