{"record":{"id":"93be2ecdb3aa2d29","repo":"RocketChat/Rocket.Chat","slug":"emoji-not-found","errorCode":null,"errorMessage":"Emoji not found.","messagePattern":"Emoji not found\\.","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/api/v1/emoji-custom.ts","lineNumber":254,"sourceCode":"\t\tasync function action() {\n\t\t\tconst emoji = await getUploadFormData(\n\t\t\t\t{\n\t\t\t\t\trequest: this.request,\n\t\t\t\t},\n\t\t\t\t{ field: 'emoji', sizeLimit: settings.get('FileUpload_MaxFileSize'), fileOptional: true },\n\t\t\t);\n\n\t\t\tconst { fields, fileBuffer, mimetype } = emoji;\n\n\t\t\tif (!fields._id) {\n\t\t\t\tthrow new Meteor.Error('The required \"_id\" query param is missing.');\n\t\t\t}\n\n\t\t\tconst emojiToUpdate = await EmojiCustom.findOneById<Pick<IEmojiCustom, 'name' | 'extension'>>(fields._id, {\n\t\t\t\tprojection: { name: 1, extension: 1 },\n\t\t\t});\n\t\t\tif (!emojiToUpdate) {\n\t\t\t\tthrow new Meteor.Error('Emoji not found.');\n\t\t\t}\n\n\t\t\tconst emojiData: EmojiData = {\n\t\t\t\tpreviousName: emojiToUpdate.name,\n\t\t\t\tpreviousExtension: emojiToUpdate.extension,\n\t\t\t\taliases: fields.aliases || '',\n\t\t\t\tname: fields.name,\n\t\t\t\textension: fields.extension,\n\t\t\t\t_id: fields._id,\n\t\t\t\tnewFile: false,\n\t\t\t};\n\n\t\t\tconst isNewFile = fileBuffer?.length && !!mimetype;\n\t\t\tif (isNewFile) {\n\t\t\t\temojiData.newFile = isNewFile;\n\t\t\t\tconst isUploadable = await Media.isImage(fileBuffer);\n\t\t\t\tif (!isUploadable) {\n\t\t\t\t\tthrow new Meteor.Error('emoji-is-not-image', \"Emoji file provided cannot be uploaded since it's not an image\");","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/api/v1/emoji-custom.ts#L236-L272","documentation":"Thrown by POST emoji-custom.update when EmojiCustom.findOneById(fields._id) returns null - the multipart _id field does not match any custom-emoji document. The handler needs the existing emoji to capture previousName/previousExtension for file cleanup, so a dangling id is a hard failure.","triggerScenarios":"POST emoji-custom.update with an _id from a different workspace, an emoji that was already deleted, an id copied with extra whitespace/quotes, or the name of the emoji passed instead of its _id.","commonSituations":"Stale cached emoji lists after an admin re-imported or pruned emojis; scripts generated against a dev environment being run against production; confusing the emoji name ('myemoji') with the document _id; concurrent deletion by another admin between list and update.","solutions":["Re-fetch the current id via GET emoji-custom.list (or emoji-custom.all) right before updating and use that _id","Confirm the emoji still exists and you are pointing at the same server/user-auth-scope that listed it","Trim and validate the _id string (24 hex chars for standard Mongo ObjectIds) before sending"],"exampleFix":"// before\nawait updateEmoji({ _id: 'myemoji' }); // name used as id -> not found\n\n// after\nconst { emojis } = await sdk.get('emoji-custom.all');\nconst emoji = emojis.update?.[0] ?? emojis.find((e) => e.name === 'myemoji');\nif (!emoji) throw new Error('emoji does not exist');\nawait updateEmoji({ _id: emoji._id });","handlingStrategy":"try-catch","validationCode":"const exists = await sdk.get('emoji-custom.list', { query: JSON.stringify({ _id: emojiId }) });\nif (!exists.emojis.update.length) throw new Error(`emoji ${emojiId} no longer exists`);","typeGuard":null,"tryCatchPattern":"try {\n  await sdk.post('emoji-custom.update', form);\n} catch (e) {\n  if (e.message === 'Emoji not found.') {\n    const fresh = await resolveEmojiIdByName(name); // re-list and rebuild form with current _id\n    if (!fresh) return; // emoji was deleted; skip\n    await sdk.post('emoji-custom.update', rebuildForm(form, fresh));\n  } else throw e;\n}","preventionTips":["Treat emoji ids as ephemeral: resolve name -> _id via emoji-custom.list in the same run","In long-lived automation, refresh the emoji map on a schedule or on every not-found","Log the _id you sent so mismatches with the server are diagnosable"],"tags":["rest-api","emoji-custom","not-found","stale-id"],"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-23T08:17:48.524Z"}