RocketChat/Rocket.Chat · error · Error
error-visitor-not-found
error-visitor-not-found
Error message
error-visitor-not-found
What it means
closeBlockedRoom resolves the visitor via LivechatVisitors.findOneById(association.visitorId) before closing the associated room; if the visitor document is gone it throws 'error-visitor-not-found'. Contact records can outlive their visitor documents (deletion, imports), producing this during block flows.
Solutions
- Verify the visitor exists (visitors API / LivechatVisitors.findOneById) before blocking
- Repair the data: re-create the visitor or remove the orphaned contact
- If the flow allows, skip room-closing when the visitor is gone
Defensive patterns
Strategy: validation
Validate before calling
import { LivechatVisitors } from '@rocket.chat/models';
const visitor = await LivechatVisitors.findOneById(association.visitorId);
if (!visitor) {
throw new Error('visitor document missing - repair or skip room closing');
}
await closeBlockedRoom(association, user); Try / catch
try {
await closeBlockedRoom(association, user);
} catch (error) {
if (error instanceof Error && error.message === 'error-visitor-not-found') {
// orphaned contact: log data inconsistency instead of failing the whole block flow
logger.warn('contact without visitor', association);
return;
}
throw error;
} Prevention
- Purge or repair contacts whose visitor documents were deleted
- Validate visitor existence before block operations that cascade into room closing
- Watch retention/cleanup jobs that delete visitors but not contacts
When it happens
Trigger: Blocking a contact whose contact record exists but whose visitor document was deleted; a visitorId copied from another workspace or import.
Common situations: Visitors purged by retention/cleanup jobs while contacts remain; data imports that created contacts without matching visitor docs.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- error-contact-not-found
- error-contact-not-found
- error-contact-not-found
- error-contact-not-found
- department-not-found
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/985695e06f666ba4.
Report an issue: GitHub.
Appendix: source
Thrown at apps/meteor/ee/server/api/v1/omnichannel/lib/contacts.ts:26
export async function changeContactBlockStatus({ block, visitor }: { visitor: ILivechatContactVisitorAssociation; block: boolean }) {
const result = await LivechatContacts.setChannelBlockStatus(visitor, block);
if (!result.modifiedCount) {
throw new Error('error-contact-not-found');
}
}
export function ensureSingleContactLicense() {
if (!License.hasModule('contact-id-verification')) {
throw new Error('error-action-not-allowed');
}
}
export async function closeBlockedRoom(association: ILivechatContactVisitorAssociation, user: IUser) {
const visitor = await LivechatVisitors.findOneById(association.visitorId);
if (!visitor) {
throw new Error('error-visitor-not-found');
}
const room = await LivechatRooms.findOneOpenByContactChannelVisitor(association);
if (!room) {
return;
}
return closeRoom({ room, visitor, comment: i18n.t('close-blocked-room-comment'), user });
}
View on GitHub (pinned to b2c16d5842)