{"record":{"id":"5b8139c117ba1d50","repo":"RocketChat/Rocket.Chat","slug":"error-creating-custom-user-status","errorCode":"error-creating-custom-user-status","errorMessage":"Error creating custom user status","messagePattern":"Error creating custom user status","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/api/v1/custom-user-status.ts","lineNumber":171,"sourceCode":"\t\tbody: isCustomUserStatusCreateProps,\n\t\tresponse: {\n\t\t\t200: customUserStatusCreateResponseSchema,\n\t\t\t400: validateBadRequestErrorResponse,\n\t\t\t401: validateUnauthorizedErrorResponse,\n\t\t\t403: validateForbiddenErrorResponse,\n\t\t},\n\t},\n\tasync function action() {\n\t\tconst userStatusData = {\n\t\t\tname: this.bodyParams.name,\n\t\t\tstatusType: this.bodyParams.statusType || '',\n\t\t};\n\n\t\tawait insertOrUpdateUserStatus(this.userId, userStatusData);\n\n\t\tconst customUserStatus = await CustomUserStatus.findOneByName(userStatusData.name);\n\t\tif (!customUserStatus) {\n\t\t\tthrow new Meteor.Error('error-creating-custom-user-status', 'Error creating custom user status');\n\t\t}\n\n\t\treturn API.v1.success({\n\t\t\tcustomUserStatus,\n\t\t});\n\t},\n);\n\nconst isCustomUserStatusDeleteProps = ajv.compile<{ customUserStatusId: string }>({\n\ttype: 'object',\n\tproperties: {\n\t\tcustomUserStatusId: { type: 'string', minLength: 1 },\n\t},\n\trequired: ['customUserStatusId'],\n\tadditionalProperties: false,\n});\n\nconst customUserStatusDeleteResponseSchema = ajv.compile<void>({","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/server/api/v1/custom-user-status.ts#L153-L189","documentation":"Thrown by POST custom-user-status.create after insertOrUpdateUserStatus ran but CustomUserStatus.findOneByName(name) returns null. The body was already AJV-validated, so this is a consistency failure: the insert did not yield a findable record. Likely a race, a masked write error, or a name lookup mismatch (case/whitespace).","triggerScenarios":"Another process deletes the status between insert and findOneByName; insertOrUpdateUserStatus silently swallowed a DB error; the stored name differs from the queried name due to trimming/case collation.","commonSituations":"Concurrent admin operations; DB connectivity blip during insert; duplicate name with different casing already present.","solutions":["Retry the create request once.","Inspect server logs for errors emitted by insertOrUpdateUserStatus.","Check whether a status with the same name (any case) already exists and pick a unique name.","If persistent, treat as a server fault (500) and escalate to an admin."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// pre-check that no status with the same name (case-insensitive) exists\nconst existing = await CustomUserStatus.findOneByName(name.trim());\nif (existing) { /* pick another name */ }","typeGuard":null,"tryCatchPattern":"try { await createCustomUserStatus({ name, statusType }); }\ncatch (e) {\n  if (isApiError(e, 'error-creating-custom-user-status')) { /* retry once, then surface server error */) }\n  else throw e;\n}","preventionTips":["Treat this code as a server-side consistency fault, not an input error.","Check server logs for insertOrUpdateUserStatus failures.","Avoid concurrent creates of the same name."],"tags":["custom-user-status","rest-api","data-integrity","concurrency"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}