{"record":{"id":"accc852e4b4ed9f9","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-email-inbox","errorCode":null,"errorMessage":"error-invalid-email-inbox","messagePattern":"error-invalid-email-inbox","errorType":"exception","errorClass":"Error","httpStatus":400,"severity":"error","filePath":"apps/meteor/server/api/lib/emailInbox.ts","lineNumber":82,"sourceCode":"\tconst updateEmailInbox = {\n\t\t$set: {\n\t\t\tactive,\n\t\t\tname,\n\t\t\temail,\n\t\t\tdescription,\n\t\t\tsenderInfo,\n\t\t\tsmtp,\n\t\t\timap,\n\t\t\t_updatedAt: new Date(),\n\t\t\t...(department !== 'All' && { department }),\n\t\t},\n\t\t...(department === 'All' && { $unset: { department: 1 as const } }),\n\t};\n\n\tconst updatedResponse = await EmailInbox.updateById(_id, updateEmailInbox);\n\n\tif (!updatedResponse) {\n\t\tthrow new Error('error-invalid-email-inbox');\n\t}\n\n\tvoid notifyOnEmailInboxChanged(\n\t\t{\n\t\t\t...updatedResponse,\n\t\t\t...(department === 'All' && { department: undefined }),\n\t\t},\n\t\t'updated',\n\t);\n\n\treturn updatedResponse;\n};\n\nexport const removeEmailInbox = async (emailInboxId: IEmailInbox['_id']): Promise<DeleteResult> => {\n\tconst removeResponse = await EmailInbox.removeById(emailInboxId);\n\n\tif (removeResponse.deletedCount) {\n\t\tvoid notifyOnEmailInboxChanged({ _id: emailInboxId }, 'removed');","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/api/lib/emailInbox.ts#L64-L100","documentation":"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.","triggerScenarios":"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.","commonSituations":"Two admins editing/deleting the same inbox, UI forms kept open past deletion, id typos or type mismatches in API callers.","solutions":["Verify the inbox exists first (email-inbox listing endpoint or db.email_inbox.findOne({ _id })).","Refresh the inbox list; if it was deleted, create it again instead of updating.","Check the _id value and type being sent."],"exampleFix":"// before\nawait updateEmailInbox({ _id, ... });\n\n// after\nconst inbox = await EmailInbox.findOneById(_id);\nif (!inbox) throw new Meteor.Error('error-invalid-email-inbox', `Inbox ${_id} not found`);\nawait updateEmailInbox({ _id, ... });","handlingStrategy":"validation","validationCode":"const inbox = await EmailInbox.findOneById(_id);\nif (!inbox) {\n\t// inbox deleted or wrong id: skip the update, offer to re-create\n}","typeGuard":"const inboxExists = async (id: string): Promise<boolean> => !!(await EmailInbox.findOneById(id));","tryCatchPattern":"try {\n\tawait updateEmailInbox({ _id, ...changes });\n} catch (e) {\n\tif (e instanceof Error && e.message === 'error-invalid-email-inbox') {\n\t\t// refresh list; if deleted, recreate instead of updating\n\t}\n\tthrow e;\n}","preventionTips":["Refresh the email-inbox record list before showing edit forms","Handle concurrent admin edits with optimistic locking UX (warn on stale ids)"],"tags":["email-inbox","omnichannel","validation"],"backgroundTag":"entity-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}