RocketChat/Rocket.Chat · error · Error

error-invalid-email-inbox

Error message

error-invalid-email-inbox

What it means

The update-email-inbox flow builds the update document and calls EmailInbox.updateById(_id, update), which is a findOneAndUpdate on { _id } with returnDocument 'after'. A falsy return means no document matched — there is no email inbox with that _id — so the flow throws error-invalid-email-inbox and skips the notifyOnEmailInboxChanged propagation.

Source

Thrown at apps/meteor/server/api/lib/emailInbox.ts:82

	const updateEmailInbox = {
		$set: {
			active,
			name,
			email,
			description,
			senderInfo,
			smtp,
			imap,
			_updatedAt: new Date(),
			...(department !== 'All' && { department }),
		},
		...(department === 'All' && { $unset: { department: 1 as const } }),
	};

	const updatedResponse = await EmailInbox.updateById(_id, updateEmailInbox);

	if (!updatedResponse) {
		throw new Error('error-invalid-email-inbox');
	}

	void notifyOnEmailInboxChanged(
		{
			...updatedResponse,
			...(department === 'All' && { department: undefined }),
		},
		'updated',
	);

	return updatedResponse;
};

export const removeEmailInbox = async (emailInboxId: IEmailInbox['_id']): Promise<DeleteResult> => {
	const removeResponse = await EmailInbox.removeById(emailInboxId);

	if (removeResponse.deletedCount) {
		void notifyOnEmailInboxChanged({ _id: emailInboxId }, 'removed');

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Verify the inbox exists first (email-inbox listing endpoint or db.email_inbox.findOne({ _id })).
  2. Refresh the inbox list; if it was deleted, create it again instead of updating.
  3. Check the _id value and type being sent.

Example fix

// before
await updateEmailInbox({ _id, ... });

// after
const inbox = await EmailInbox.findOneById(_id);
if (!inbox) throw new Meteor.Error('error-invalid-email-inbox', `Inbox ${_id} not found`);
await updateEmailInbox({ _id, ... });
Defensive patterns

Strategy: validation

Validate before calling

const inbox = await EmailInbox.findOneById(_id);
if (!inbox) {
	// inbox deleted or wrong id: skip the update, offer to re-create
}

Type guard

const inboxExists = async (id: string): Promise<boolean> => !!(await EmailInbox.findOneById(id));

Try / catch

try {
	await updateEmailInbox({ _id, ...changes });
} catch (e) {
	if (e instanceof Error && e.message === 'error-invalid-email-inbox') {
		// refresh list; if deleted, recreate instead of updating
	}
	throw e;
}

Prevention

When it happens

Trigger: Updating an email inbox whose _id no longer exists in the email_inbox collection: deleted concurrently by another admin, stale edit form after deletion, or a wrong _id passed by an integration.

Common situations: Two admins editing/deleting the same inbox, UI forms kept open past deletion, id typos or type mismatches in API callers.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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