RocketChat/Rocket.Chat · error · Meteor.Error

error-unit-not-found

error-unit-not-found

Error message

Error! No Active Business Unit found with id: ${businessUnit}

What it means

Thrown by the checkUnitsFromUser patch in unit.ts:15 — an enterprise extension of the core unit-visibility check. When a businessUnit id is supplied and the user's scoped units (getUnitsFromUser) do not contain a unit with that _id (findOneById returns null within the scope), it aborts. Meteor.Error 'error-unit-not-found' with a descriptive message including the offending businessUnit id.

Source

Thrown at apps/meteor/ee/server/lib/omnichannel/unit.ts:15

import { LivechatUnit } from '@rocket.chat/models';
import { getUnitsFromUser } from '@rocket.chat/omni-core-ee';
import { Meteor } from 'meteor/meteor';

import type { CheckUnitsFromUser } from '../../../../server/api/v1/omnichannel/lib/livechat';
import { checkUnitsFromUser } from '../../../../server/api/v1/omnichannel/lib/livechat';

checkUnitsFromUser.patch(async (_next, { businessUnit, userId }: CheckUnitsFromUser) => {
	if (!businessUnit) {
		return;
	}
	const unitsFromUser = await getUnitsFromUser(userId);
	const unit = await LivechatUnit.findOneById(businessUnit, { projection: { _id: 1 } }, { unitsFromUser });
	if (!unit) {
		throw new Meteor.Error('error-unit-not-found', `Error! No Active Business Unit found with id: ${businessUnit}`);
	}
});

View on GitHub (pinned to f9d3ec372b)

Solutions

  1. Ensure the businessUnit id is in getUnitsFromUser(userId) before triggering the operation.
  2. Reassign the user as a monitor of the target business unit, or clear the businessUnit reference.
  3. Catch Meteor.Error 'error-unit-not-found' at the routing boundary and fall back to unscoped behavior.

Example fix

// before
await someOperation({ businessUnit, userId });

// after
if (businessUnit) {
  const mine = await getUnitsFromUser(userId);
  const exists = await LivechatUnit.findOneById(businessUnit, { projection: { _id: 1 } }, { unitsFromUser: mine });
  if (!exists) throw new Error('businessUnit not in user scope');
}
await someOperation({ businessUnit, userId });
Defensive patterns

Strategy: validation

Validate before calling

if (businessUnit) {
  const mine = await getUnitsFromUser(userId);
  const unit = await LivechatUnit.findOneById(businessUnit, { projection: { _id: 1 } }, { unitsFromUser: mine });
  if (!unit) throw new Error('businessUnit not in user scope');
}

Type guard

const isUnitInScope = async (businessUnit: string, userId: string) => {
  const mine = await getUnitsFromUser(userId);
  return Boolean(await LivechatUnit.findOneById(businessUnit, { projection: { _id: 1 } }, { unitsFromUser: mine }));
};

Try / catch

try { await op({ businessUnit, userId }); }
catch (e) {
  if (e instanceof Meteor.Error && e.error === 'error-unit-not-found') { /* clear unit ref */ return; }
  throw e;
}

Prevention

When it happens

Trigger: Any core flow that calls checkUnitsFromUser with a businessUnit id the current user is not permitted to see (e.g. routing a conversation to a unit outside their monitor scope). Triggers during room routing, agent assignment, or department operations that pass a businessUnit context.

Common situations: Agent reassigned across business units without having the new unit in their scope; stale businessUnit id stored on a department after the unit was deleted; permission scope narrowed by an admin.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@f9d3ec372b (2026-08-12). Data as JSON: /api/errors/641854bbe16d63b0. Report an issue: GitHub.