{"record":{"id":"082b550350c05d68","repo":"RocketChat/Rocket.Chat","slug":"invalid-user-082b55","errorCode":"invalid-user","errorMessage":"invalid-user","messagePattern":"invalid-user","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/resetUserE2EKey.ts","lineNumber":14,"sourceCode":"import { api } from '@rocket.chat/core-services';\nimport { Subscriptions, Users, Rooms } from '@rocket.chat/models';\nimport { Meteor } from 'meteor/meteor';\n\nimport { i18n } from './i18n';\nimport { isUserIdFederated } from './isUserIdFederated';\nimport * as Mailer from './notifications/email/api';\nimport { notifyOnUserChange, notifyOnSubscriptionChangedByUserId } from './notifyListener';\nimport { settings } from '../settings';\n\nconst sendResetNotification = async function (uid: string): Promise<void> {\n\tconst user = await Users.findOneById(uid, {});\n\tif (!user) {\n\t\tthrow new Meteor.Error('invalid-user');\n\t}\n\n\tconst language = user.language || settings.get('Language') || 'en';\n\tconst addresses = user.emails?.filter(({ verified }) => verified).map((e) => e.address);\n\tif (!addresses?.length) {\n\t\treturn;\n\t}\n\n\tconst t = i18n.getFixedT(language);\n\tconst text = `\n\t${t('Your_e2e_key_has_been_reset')}\n\n\t${t('E2E_Reset_Email_Content')}\n\t`;\n\tconst html = `\n\t\t<p>${t('Your_e2e_key_has_been_reset')}</p>\n\t\t<p>${t('E2E_Reset_Email_Content')}</p>\n\t`;","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/resetUserE2EKey.ts#L1-L32","documentation":"Meteor.Error('invalid-user') thrown by sendResetNotification (the notification helper of resetUserE2EEncriptionKey) when Users.findOneById(uid) returns nothing. The E2E key reset notification cannot proceed for a user that does not exist.","triggerScenarios":"Calling resetUserE2EEncriptionKey(uid, true) with a deleted or never-existing user id, or a user deleted between the admin action and processing.","commonSituations":"Admin resets an E2E key from a stale user list; background jobs referencing deleted users; user deleted while the reset flow is in flight.","solutions":["Verify the user exists with a fresh lookup immediately before triggering the reset.","Pass notifyUser=false when resetting keys for users that may have been deleted.","In queued jobs, drop work items whose user no longer exists instead of failing."],"exampleFix":"// before\nawait resetUserE2EEncriptionKey(uid, true); // throws invalid-user for deleted users\n\n// after\nconst user = await Users.findOneById(uid, { projection: { _id: 1 } });\nif (user) {\n  await resetUserE2EEncriptionKey(uid, true);\n}","handlingStrategy":"validation","validationCode":"const user = await Users.findOneById(uid, { projection: { _id: 1 } });\nif (!user) {\n  // skip the E2E key reset / notification: user is gone\n}","typeGuard":null,"tryCatchPattern":"try {\n  await resetUserE2EEncriptionKey(uid, true);\n} catch (error: any) {\n  if (error?.error === 'invalid-user') {\n    // drop the work item; nothing to reset\n  }\n}","preventionTips":["Re-check user existence immediately before triggering key resets.","Pass notifyUser=false when resetting keys for users that may have been deleted.","In background jobs, drop work items whose user no longer exists."],"tags":["users","e2e-encryption","validation"],"backgroundTag":"user-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}