From 8b741d20f011fa192a4b56a556dc21da348cb98c Mon Sep 17 00:00:00 2001 From: dschom Date: Tue, 9 Aug 2022 09:48:57 -0700 Subject: [PATCH] fix(content-server): Fix broken l10n-extraction Because: - The `npx grunt l10n-extract` was breaking due to optional chaining syntax present in sentry.js - The l10n-extract uses the acorn parser under the hood, which doesn't appear to like optional chaining syntax. This Commit: - Ensures there is no optional chaining syntax present in the sentry.js file. --- .../fxa-content-server/server/lib/sentry.js | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/fxa-content-server/server/lib/sentry.js b/packages/fxa-content-server/server/lib/sentry.js index fac37a405b3..c5116b274bc 100644 --- a/packages/fxa-content-server/server/lib/sentry.js +++ b/packages/fxa-content-server/server/lib/sentry.js @@ -89,16 +89,29 @@ if (config.get('sentry.dsn')) { */ function tryCaptureValidationError(err) { try { - const errorDetails = - err?.details instanceof Map && err?.details?.get('body'); + // Try to get error details. This might not be present. + let errorDetails = null; + if (err != null && err.details instanceof Map) { + errorDetails = err.details.get('body'); + } if (errorDetails) { const message = `${errorDetails}`; const validationError = errorDetails.details.reduce((a, v) => { - return { - ...a, - [v?.path?.join('.')]: `reason: ${v.type} - ${v.message}`, - }; + // Try to get the key for the field that failed validation and update + // the error state + if (v && Array.isArray(v.path)) { + const key = v.path.join('.'); + + if (key) { + return { + ...a, + [key]: `reason: ${v.type} - ${v.message}`, + }; + } + } + + return a; }, {}); Sentry.withScope((scope) => {