{"record":{"id":"99f1e75f805e207b","repo":"RocketChat/Rocket.Chat","slug":"custom-emoji-error-invalid-emoji","errorCode":"Custom_Emoji_Error_Invalid_Emoji","errorMessage":"Invalid emoji","messagePattern":"Invalid emoji","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/media/deleteEmojiCustom.ts","lineNumber":25,"sourceCode":"import { hasPermissionAsync } from '../../lib/authorization/hasPermission';\nimport { methodDeprecationLogger } from '../../lib/deprecationWarningLogger';\nimport { RocketChatFileEmojiCustomInstance } from '../../lib/media/emoji-custom/startup/emoji-custom';\n\ndeclare module '@rocket.chat/ddp-client' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {\n\t\tdeleteEmojiCustom(emojiID: ICustomEmojiDescriptor['_id']): boolean;\n\t}\n}\n\nexport const deleteEmojiCustom = async (userId: string, emojiID: ICustomEmojiDescriptor['_id']): Promise<boolean> => {\n\tif (!(await hasPermissionAsync(userId, 'manage-emoji'))) {\n\t\tthrow new Meteor.Error('not_authorized');\n\t}\n\n\tconst emoji = await EmojiCustom.findOneById(emojiID);\n\tif (emoji == null) {\n\t\tthrow new Meteor.Error('Custom_Emoji_Error_Invalid_Emoji', 'Invalid emoji', {\n\t\t\tmethod: 'deleteEmojiCustom',\n\t\t});\n\t}\n\n\tawait RocketChatFileEmojiCustomInstance.deleteFile(encodeURIComponent(`${emoji.name}.${emoji.extension}`));\n\tawait EmojiCustom.removeById(emojiID);\n\tvoid api.broadcast('emoji.deleteCustom', emoji);\n\n\treturn true;\n};\n\nMeteor.methods<ServerMethods>({\n\tasync deleteEmojiCustom(emojiID) {\n\t\tmethodDeprecationLogger.method('deleteEmojiCustom', '9.0.0', '/v1/emoji-custom.delete');\n\t\tif (!this.userId) {\n\t\t\tthrow new Meteor.Error('not_authorized');\n\t\t}\n","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/media/deleteEmojiCustom.ts#L7-L43","documentation":"Thrown by deleteEmojiCustom when EmojiCustom.findOneById(emojiID) returns null — the id does not match any custom emoji. The permission check has already passed at this point, so this error is purely a bad-record-id problem.","triggerScenarios":"Deleting with a mistyped, truncated, or already-removed emoji id; UI holding a stale emoji list after another admin deleted the same emoji; ids copied from a different workspace.","commonSituations":"Double-submit of a delete form; concurrent emoji management; migration scripts carrying old emoji ids.","solutions":["List current emojis (GET /v1/emoji-custom.list) and copy the exact _id","Refresh the emoji picker/admin list and retry with a live id","Treat a repeat failure as 'already deleted' and reconcile your local state"],"exampleFix":"// before\nawait Meteor.callAsync('deleteEmojiCustom', 'wrong-or-stale-id');\n\n// after\nconst res = await fetch('/api/v1/emoji-custom.list', { headers });\nconst { emojis } = await res.json();\nconst emoji = emojis.find((e) => e._id === emojiId);\nif (!emoji) throw new Error('Unknown emoji id');\nawait Meteor.callAsync('deleteEmojiCustom', emoji._id);","handlingStrategy":"validation","validationCode":"const res = await fetch('/api/v1/emoji-custom.list', { headers });\nconst { emojis } = await res.json();\nif (!emojis.some((e) => e._id === emojiId)) {\n  throw new Error('Unknown emoji id');\n}","typeGuard":"const isKnownEmojiId = (emojis: { _id: string }[], id: string): boolean =>\n  emojis.some((e) => e._id === id);","tryCatchPattern":"try {\n  await Meteor.callAsync('deleteEmojiCustom', emojiId);\n} catch (err) {\n  if (err instanceof Meteor.Error && err.error === 'Custom_Emoji_Error_Invalid_Emoji') {\n    // id is wrong or already deleted: refresh the emoji list, do not retry\n    return;\n  }\n  throw err;\n}","preventionTips":["Delete emojis using ids from a fresh emoji-custom.list call","Guard double-submits in the UI to avoid racing deletes","Treat repeat hits as already-deleted and reconcile state"],"tags":["emoji","not-found","meteor-methods"],"backgroundTag":"resource-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}