{"record":{"id":"b246253b2def2cff","repo":"RocketChat/Rocket.Chat","slug":"e-message","errorCode":null,"errorMessage":"e.message","messagePattern":"e\\.message","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/users/registerUser.ts","lineNumber":116,"sourceCode":"\tawait validateEmailDomain(formData.email);\n\n\tconst userData = {\n\t\temail: trim(formData.email.toLowerCase()),\n\t\tpassword: formData.pass,\n\t\t...(formData.name?.trim() && { name: formData.name?.trim() }),\n\t\treason: formData.reason,\n\t};\n\n\tlet userId;\n\ttry {\n\t\tuserId = await Accounts.createUserAsync(userData);\n\t} catch (e) {\n\t\tif (e instanceof Meteor.Error) {\n\t\t\tthrow e;\n\t\t}\n\n\t\tif (e instanceof Error) {\n\t\t\tthrow new Meteor.Error(e.message);\n\t\t}\n\n\t\tthrow new Meteor.Error(String(e));\n\t}\n\n\tconst reason = trim(formData.reason);\n\tif (manuallyApproveNewUsers && reason) {\n\t\tawait Users.setReason(userId, reason);\n\t}\n\n\ttry {\n\t\tAccounts.sendVerificationEmail(userId, userData.email);\n\t} catch (error) {\n\t\t// throw new Meteor.Error 'error-email-send-failed', 'Error trying to send email: ' + error.message, { method: 'registerUser', message: error.message }\n\t}\n\n\treturn userId;\n};","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/users/registerUser.ts#L98-L134","documentation":"Dynamic rethrow: Accounts.createUserAsync rejected with a non-Meteor plain Error, so registerUser wraps e.message as the error text with NO stable error code. Typical origins are lower-level failures such as MongoDB duplicate-key (E11000 on users email/username) or custom accounts-validateNewUser hooks throwing plain Errors. Because there is no 'error-...' code, callers must match on the message.","triggerScenarios":"Registering with an email or username that collides at the Mongo index level (the accounts-base 'Email already exists' variant is a Meteor.Error and is rethrown unchanged; driver-level E11000 lands here); an accounts package hook or third-party plugin rejecting with `throw new Error(...)`.","commonSituations":"Double-submitted signup forms racing each other; custom username-normalization hooks throwing plain Errors; sharded/multi-instance deployments where the race window between check and insert widens.","solutions":["Inspect the wrapped message: 'E11000 duplicate key' means the email/username is taken - prompt the user and pre-check availability.","Ensure custom onCreateUser/validateNewUser hooks throw Meteor.Error (with a code), not plain Error, so clients get a stable code.","Disable the submit button while the call is in flight to prevent duplicate races."],"exampleFix":"// before: hook throws a plain Error, surfaces as opaque code-less Meteor.Error\nAccounts.validateNewUser(() => { throw new Error('bad domain'); });\n\n// after: throw a coded Meteor.Error so registerUser rethrows it unchanged\nAccounts.validateNewUser(() => {\n  throw new Meteor.Error('error-invalid-email-domain', 'Email domain not allowed');\n});","handlingStrategy":"try-catch","validationCode":"const taken = await checkUsernameAvailability(username); // e.g. GET /api/v1/users.info?username=...\nconst emailTaken = await checkEmailAvailability(email);\nif (taken || emailTaken) return showInlineError('Username or email already in use');","typeGuard":"const isMeteorError = (e: unknown, code?: string): e is Meteor.Error =>\n  typeof e === 'object' && e !== null && 'error' in e && (code === undefined || (e as Meteor.Error).error === code);","tryCatchPattern":"try {\n  await Meteor.callAsync('registerUser', formData);\n} catch (e) {\n  if (isMeteorError(e, 'error-user-registration-disabled')) { /* handled elsewhere */ }\n  // code-less errors come from createUserAsync wrapping: inspect the message\n  const detail = (e as Meteor.Error).reason ?? String((e as Meteor.Error).error);\n  if (/E11000 duplicate key/i.test(detail)) showInlineError('Email or username already registered');\n  else showError(detail);\n}","preventionTips":["Pre-check email/username availability before submitting","Make custom accounts hooks throw Meteor.Error with stable codes instead of plain Error","Disable submit buttons while registration is in flight to avoid duplicate-race E11000"],"tags":["registration","accounts","error-wrapping","duplicate-key"],"backgroundTag":"user-creation-failed","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"}