{"record":{"id":"f1cd46a081037b88","repo":"RocketChat/Rocket.Chat","slug":"custom-user-status-error-name-already-in-use","errorCode":"Custom_User_Status_Error_Name_Already_In_Use","errorMessage":"The custom user status name is already in use","messagePattern":"The custom user status name is already in use","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/users/insertOrUpdateUserStatus.ts","lineNumber":60,"sourceCode":"\n\t// allow all characters except >, <, &, \", '\n\t// more practical than allowing specific sets of characters; also allows foreign languages\n\tconst nameValidation = /[><&\"']/;\n\n\tif (nameValidation.test(userStatusData.name)) {\n\t\tthrow new Meteor.Error('error-input-is-not-a-valid-field', `${userStatusData.name} is not a valid name`, {\n\t\t\tmethod: 'insertOrUpdateUserStatus',\n\t\t\tinput: userStatusData.name,\n\t\t\tfield: 'Name',\n\t\t});\n\t}\n\n\tconst conflictingUserStatus = userStatusData._id\n\t\t? await CustomUserStatus.findOneByNameExceptId(userStatusData.name, userStatusData._id, { projection: { _id: 1 } })\n\t\t: await CustomUserStatus.findOneByName(userStatusData.name, { projection: { _id: 1 } });\n\n\tif (conflictingUserStatus) {\n\t\tthrow new Meteor.Error('Custom_User_Status_Error_Name_Already_In_Use', 'The custom user status name is already in use', {\n\t\t\tmethod: 'insertOrUpdateUserStatus',\n\t\t});\n\t}\n\n\tconst validStatusTypes = ['online', 'away', 'busy', 'offline'];\n\tif (userStatusData.statusType && validStatusTypes.indexOf(userStatusData.statusType) < 0) {\n\t\tthrow new Meteor.Error('error-input-is-not-a-valid-field', `${userStatusData.statusType} is not a valid status type`, {\n\t\t\tmethod: 'insertOrUpdateUserStatus',\n\t\t\tinput: userStatusData.statusType,\n\t\t\tfield: 'StatusType',\n\t\t});\n\t}\n\n\tif (!userStatusData._id) {\n\t\t// insert user status\n\t\tconst createUserStatus: InsertionModel<ICustomUserStatus> = {\n\t\t\tname: userStatusData.name,\n\t\t\tstatusType: userStatusData.statusType,","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/users/insertOrUpdateUserStatus.ts#L42-L78","documentation":"A custom user status with the same name already exists: the method found a conflicting document via findOneByName (on create) or findOneByNameExceptId (on update, excluding the record being edited). Custom status names must be unique.","triggerScenarios":"Creating a status whose name matches an existing one; renaming a status to a name another status already uses.","commonSituations":"Two admins creating similar statuses concurrently; renaming into an existing name; re-running an import/setup script that creates the same status twice.","solutions":["List existing statuses first (listCustomUserStatus) and pick a unique name before saving","When updating, exclude the current record's _id from your duplicate check","Catch this code and surface 'name already in use' next to the input field"],"exampleFix":"// before\nawait Meteor.callAsync('insertOrUpdateUserStatus', { name });\n\n// after — pre-check for duplicates (still keep the catch for races)\nconst existing = (await Meteor.callAsync('listCustomUserStatus')).some(\n\t(s) => s.name === name && s._id !== editingId,\n);\nif (existing) {\n\tshowInlineError('name already in use');\n\treturn;\n}\nawait Meteor.callAsync('insertOrUpdateUserStatus', { name });","handlingStrategy":"try-catch","validationCode":"const existing = (await Meteor.callAsync<ICustomUserStatus[]>('listCustomUserStatus'))\n\t.some((s) => s.name === name && s._id !== editingId);\nif (existing) {\n\tsetFieldError('name', 'Name already in use');\n\treturn;\n}","typeGuard":null,"tryCatchPattern":"try {\n\tawait Meteor.callAsync('insertOrUpdateUserStatus', data);\n} catch (err) {\n\tif (err instanceof Meteor.Error && err.error === 'Custom_User_Status_Error_Name_Already_In_Use') {\n\t\t// server-authoritative duplicate — prompt for a different name (race with pre-check)\n\t}\n}","preventionTips":["Pre-check names against listCustomUserStatus before save, but keep the catch for races","When renaming, exclude the edited record's _id from the duplicate check","Make create-status forms idempotent on retry instead of resubmitting the same name"],"tags":["meteor","custom-user-status","uniqueness","duplicate"],"backgroundTag":"duplicate-name-conflict","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"}