{"record":{"id":"809a47d039fffbc0","repo":"RocketChat/Rocket.Chat","slug":"error-updating-custom-user-status","errorCode":"error-updating-custom-user-status","errorMessage":"Error updating custom user status","messagePattern":"Error updating custom user status","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/api/v1/custom-user-status.ts","lineNumber":269,"sourceCode":"\t\tconst userStatusData = {\n\t\t\t_id: this.bodyParams._id,\n\t\t\tname: this.bodyParams.name,\n\t\t\tstatusType: this.bodyParams.statusType || '',\n\t\t};\n\n\t\tconst customUserStatusToUpdate = await CustomUserStatus.findOneById(userStatusData._id);\n\n\t\t// Ensure the message exists\n\t\tif (!customUserStatusToUpdate) {\n\t\t\treturn API.v1.failure(`No custom user status found with the id of \"${userStatusData._id}\".`);\n\t\t}\n\n\t\tawait insertOrUpdateUserStatus(this.userId, userStatusData);\n\n\t\tconst customUserStatus = await CustomUserStatus.findOneById(userStatusData._id);\n\n\t\tif (!customUserStatus) {\n\t\t\tthrow new Meteor.Error('error-updating-custom-user-status', 'Error updating custom user status');\n\t\t}\n\n\t\treturn API.v1.success({\n\t\t\tcustomUserStatus,\n\t\t});\n\t},\n);\n\nexport type CustomUserStatusEndpoints = ExtractRoutesFromAPI<typeof customUserStatusEndpoints>;\n\ndeclare module '@rocket.chat/rest-typings' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface\n\tinterface Endpoints extends CustomUserStatusEndpoints {}\n}\n","sourceCodeStart":251,"sourceCodeEnd":284,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/api/v1/custom-user-status.ts#L251-L284","documentation":"Thrown by POST custom-user-status.update as a post-condition check: the endpoint first returns an explicit failure if no status with the given _id exists, then runs insertOrUpdateUserStatus and re-reads the record by _id; if that read comes back empty it throws Meteor.Error('error-updating-custom-user-status'). This means the update path itself dropped or renamed the record — typically the body changed the name to one that collides with another existing status.","triggerScenarios":"POSTing custom-user-status.update with { _id, name } where name collides (case-insensitively) with a different existing status so the underlying update silently does not apply, or the record is deleted concurrently between the pre-check and the read-back.","commonSituations":"Rename flows that hit an existing name; two admins editing statuses at once; seeding scripts that update by stale _id after the workspace was re-seeded.","solutions":["Confirm the target _id still exists via custom-user-status.list before updating.","When renaming, verify the new name is not already taken (case-insensitive) by another status.","Re-fetch the list on this error and reconcile your local cache instead of blind-retrying."],"exampleFix":"// before\nawait api.post('custom-user-status.update', { _id, name: newName, statusType });\n\n// after — ensure the new name is free before renaming\nconst { statuses } = await api.get('custom-user-status.list');\nconst taken = statuses.some(s => s._id !== _id && s.name.toLowerCase() === newName.trim().toLowerCase());\nif (!taken) await api.post('custom-user-status.update', { _id, name: newName.trim(), statusType });","handlingStrategy":"validation","validationCode":"async function safeUpdateStatus(api, _id: string, name: string, statusType: string) {\n  const { statuses } = await api.get('custom-user-status.list');\n  const exists = statuses.some(s => s._id === _id);\n  const nameTaken = statuses.some(s => s._id !== _id && s.name.toLowerCase() === name.trim().toLowerCase());\n  if (exists && !nameTaken) await api.post('custom-user-status.update', { _id, name: name.trim(), statusType });\n}","typeGuard":null,"tryCatchPattern":"try { await api.post('custom-user-status.update', { _id, name, statusType }); }\ncatch (e) {\n  if (e.error === 'error-updating-custom-user-status') { await refreshStatuses(); /* reconcile cache */ } else throw e;\n}","preventionTips":["Check rename targets for case-insensitive collisions before submitting.","Refetch the status list when an update unexpectedly fails instead of blind-retrying."],"tags":["rocketchat","rest-api","custom-user-status","update-failed","duplicate-entry"],"backgroundTag":"resource-update-failed","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"}