RocketChat/Rocket.Chat · error · Meteor.Error

error-the-field-is-required

error-the-field-is-required

Error message

The field rid is required

What it means

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.

Source

Thrown at apps/meteor/server/lib/rooms/invites/findOrCreateInvite.ts:38

		{
			full: useDirectLink,
			cloud: !useDirectLink,
			cloud_route: 'invite',
		},
		settings.get<string>('DeepLink_Url'),
	);
}

const possibleDays = [0, 1, 7, 15, 30];
const possibleUses = [0, 1, 5, 10, 25, 50, 100];

export const findOrCreateInvite = async (userId: string, invite: Pick<IInvite, 'rid' | 'days' | 'maxUses'>) => {
	if (!userId || !invite) {
		return false;
	}

	if (!invite.rid) {
		throw new Meteor.Error('error-the-field-is-required', 'The field rid is required', {
			method: 'findOrCreateInvite',
			field: 'rid',
		});
	}

	if (!(await hasPermissionAsync(userId, 'create-invite-links', invite.rid))) {
		throw new Meteor.Error('not_authorized');
	}

	const subscription = await Subscriptions.findOneByRoomIdAndUserId(invite.rid, userId, {
		projection: { _id: 1 },
	});
	if (!subscription) {
		throw new Meteor.Error('error-invalid-room', 'The rid field is invalid', {
			method: 'findOrCreateInvite',
			field: 'rid',
		});
	}

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Ensure the invite payload includes rid before calling findOrCreateInvite
  2. Resolve the room once and use its id: { rid: room._id, days, maxUses }
  3. Validate the payload against the REST/method schema at the boundary

Example fix

// before
await findOrCreateInvite(userId, { days, maxUses });

// after
if (!invite.rid) {
  throw new Meteor.Error('error-the-field-is-required', 'The field rid is required');
}
await findOrCreateInvite(userId, invite);
Defensive patterns

Strategy: validation

Validate before calling

if (!invite?.rid) {
  throw new Meteor.Error('error-the-field-is-required', 'The field rid is required', { field: 'rid' });
}
await findOrCreateInvite(userId, invite);

Type guard

const hasRid = (invite: Pick<IInvite, 'rid' | 'days' | 'maxUses'> | undefined): invite is Pick<IInvite, 'rid' | 'days' | 'maxUses'> & { rid: string } =>
  Boolean(invite && invite.rid);

Try / catch

try {
  await findOrCreateInvite(userId, invite);
} catch (err) {
  if (err instanceof Meteor.Error && err.error === 'error-the-field-is-required' && err.details?.field === 'rid') {
    // fix the payload — room selector failed upstream
  }
  throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18). Data as JSON: /api/errors/dd00120b27003b49. Report an issue: GitHub.