{"record":{"id":"ed7a917646a78dda","repo":"RocketChat/Rocket.Chat","slug":"customoauth-failed-to-extract-email","errorCode":null,"errorMessage":"CustomOAuth: Failed to extract email","messagePattern":"CustomOAuth: Failed to extract email","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/auth-providers/custom-oauth/customOAuth.ts","lineNumber":154,"sourceCode":"\t\t\t}\n\n\t\t\treturn value as string;\n\t\t} catch (error) {\n\t\t\tthrow new Error('CustomOAuth: Failed to extract username', { cause: error });\n\t\t}\n\t}\n\n\tgetEmail(data: Record<string, any>) {\n\t\ttry {\n\t\t\tconst value = fromTemplate(this.emailField, data);\n\n\t\t\tif (!value) {\n\t\t\t\tlogger.debug({ msg: 'Email field not found in data', emailField: this.emailField, data });\n\t\t\t\tthrow new Meteor.Error('field_not_found', `Email field \"${this.emailField}\" not found in data`);\n\t\t\t}\n\t\t\treturn value as string;\n\t\t} catch (error) {\n\t\t\tthrow new Error('CustomOAuth: Failed to extract email', { cause: error });\n\t\t}\n\t}\n\n\tgetCustomName(data: Record<string, any>) {\n\t\ttry {\n\t\t\tconst value = fromTemplate(this.nameField, data);\n\n\t\t\tif (!value) {\n\t\t\t\treturn this.getName(data);\n\t\t\t}\n\n\t\t\treturn value as string;\n\t\t} catch (error) {\n\t\t\tthrow new Error('CustomOAuth: Failed to extract custom name', { cause: error });\n\t\t}\n\t}\n\n\tgetAvatarUrl(data: Record<string, any>) {","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/auth-providers/custom-oauth/customOAuth.ts#L136-L172","documentation":"Generic wrapper thrown by getEmail's catch block; the meaningful failure is error.cause, normally Meteor.Error('field_not_found') from error 637, occasionally a fromTemplate syntax error (invalid {{regex::path}} email template). It surfaces during login as the outermost error of the email-extraction step.","triggerScenarios":"emailField mapping resolves to nothing in the provider's identity payload; malformed emailField template causing fromTemplate to throw; any unexpected error inside the try block (e.g., non-object data from a weird IdP response).","commonSituations":"Debugging shows 'CustomOAuth: Failed to extract email' but the actionable detail (which field, what data) is in cause and the debug log one frame deeper.","solutions":["Inspect error.cause (field_not_found includes the emailField template) and the 'Email field not found in data' debug entry","Fix the emailField mapping or grant the email scope, then retry login","Clear emailField if the deployment does not require email-based account mapping"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n\tawait oauthLogin();\n} catch (e) {\n\tconst cause = (e as Error & { cause?: unknown }).cause;\n\tif (cause instanceof Meteor.Error && cause.error === 'field_not_found') {\n\t\t// cause.reason names the emailField — grant email scope or fix the path\n\t} else throw e;\n}","preventionTips":["Unwrap .cause: the actionable detail is field_not_found plus the debug log 'Email field not found in data'","Keep a captured sample /me payload in tests to catch schema drift early","For internal IdPs, prefer an email claim that is always present (e.g., mail on Entra ID)"],"tags":["custom-oauth","oauth","field-mapping","error-wrapping"],"backgroundTag":"oauth-field-mapping-failed","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}