{"record":{"id":"985695e06f666ba4","repo":"RocketChat/Rocket.Chat","slug":"error-visitor-not-found","errorCode":null,"errorMessage":"error-visitor-not-found","messagePattern":"error-visitor-not-found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/api/v1/omnichannel/lib/contacts.ts","lineNumber":26,"sourceCode":"export async function changeContactBlockStatus({ block, visitor }: { visitor: ILivechatContactVisitorAssociation; block: boolean }) {\n\tconst result = await LivechatContacts.setChannelBlockStatus(visitor, block);\n\n\tif (!result.modifiedCount) {\n\t\tthrow new Error('error-contact-not-found');\n\t}\n}\n\nexport function ensureSingleContactLicense() {\n\tif (!License.hasModule('contact-id-verification')) {\n\t\tthrow new Error('error-action-not-allowed');\n\t}\n}\n\nexport async function closeBlockedRoom(association: ILivechatContactVisitorAssociation, user: IUser) {\n\tconst visitor = await LivechatVisitors.findOneById(association.visitorId);\n\n\tif (!visitor) {\n\t\tthrow new Error('error-visitor-not-found');\n\t}\n\n\tconst room = await LivechatRooms.findOneOpenByContactChannelVisitor(association);\n\n\tif (!room) {\n\t\treturn;\n\t}\n\n\treturn closeRoom({ room, visitor, comment: i18n.t('close-blocked-room-comment'), user });\n}\n","sourceCodeStart":8,"sourceCodeEnd":37,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/ee/server/api/v1/omnichannel/lib/contacts.ts#L8-L37","documentation":"Thrown by closeBlockedRoom when LivechatVisitors.findOneById(association.visitorId) returns null. The blocked-contact room closure requires a valid visitor record to attribute the closure; a missing visitor halts the operation. Plain Error, code 'error-visitor-not-found'.","triggerScenarios":"Calling closeBlockedRoom with a visitor association whose visitorId does not exist in LivechatVisitors; visitor was deleted while a blocked room was still open; visitorId passed as a string ID that does not match the stored ObjectId string form.","commonSituations":"Race condition: visitor purged after the block was set; stale association cached; data inconsistency between LivechatContacts and LivechatVisitors; import that created contacts without matching visitors.","solutions":["Confirm the visitor exists via LivechatVisitors.findOneById before calling closeBlockedRoom.","Reconcile LivechatVisitors with LivechatContacts if records are inconsistent.","If the visitor was intentionally deleted, close the room via a different path (e.g. manual close) and clean up the orphaned contact association.","Validate the visitorId format/length against the stored collection."],"exampleFix":"// before: assume visitor present\nawait closeBlockedRoom(assoc, user);\n\n// after: precondition check\nconst visitor = await LivechatVisitors.findOneById(assoc.visitorId);\nif (!visitor) {\n  // reconcile or skip; do not call closeBlockedRoom\n  return;\n}\nawait closeBlockedRoom(assoc, user);","handlingStrategy":"validation","validationCode":"// Verify visitor exists before closing the blocked room\nimport { LivechatVisitors } from '@rocket.chat/models';\nconst visitor = await LivechatVisitors.findOneById(association.visitorId);\nif (!visitor) {\n  // reconcile or skip; do not call closeBlockedRoom\n  return { ok: false, reason: 'visitor-missing' };\n}\nawait closeBlockedRoom(association, user);","typeGuard":null,"tryCatchPattern":"try {\n  await closeBlockedRoom(association, user);\n} catch (e) {\n  if (e.message === 'error-visitor-not-found') {\n    // orphaned blocked room: close via fallback path\n    await fallbackCloseRoom(association, user);\n    return;\n  }\n  throw e;\n}","preventionTips":["Reconcile LivechatVisitors with LivechatContacts after imports/merges.","Validate visitorId format and existence before any room lifecycle operation."],"tags":["omnichannel","livechat","visitors","not-found"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}