From b7715f6e7011ca73f69c5b1705148ed6e4bedb76 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Wed, 29 Jul 2020 13:09:52 -0300 Subject: [PATCH] Only log error on first occurrence of missing substitution (#9096) A missing substitution for a localized message will now only log an error upon the first occurrence. Further errors are generally not useful. --- ui/app/helpers/utils/i18n-helper.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ui/app/helpers/utils/i18n-helper.js b/ui/app/helpers/utils/i18n-helper.js index a32120b4f..7fccc92cb 100644 --- a/ui/app/helpers/utils/i18n-helper.js +++ b/ui/app/helpers/utils/i18n-helper.js @@ -6,6 +6,7 @@ import * as Sentry from '@sentry/browser' const warned = {} const missingMessageErrors = {} +const missingSubstitutionErrors = {} /** * Returns a localized message for the given key @@ -55,7 +56,11 @@ export const getMessage = (localeCode, localeMessages, key, substitutions) => { return part } const substituteIndex = Number(subMatch[1]) - 1 - if (substitutions[substituteIndex] == null) { + if (substitutions[substituteIndex] == null && !missingSubstitutionErrors[localeCode]?.[key]) { + if (!missingSubstitutionErrors[localeCode]) { + missingSubstitutionErrors[localeCode] = {} + } + missingSubstitutionErrors[localeCode][key] = true const error = new Error(`Insufficient number of substitutions for message: '${phrase}'`) log.error(error) Sentry.captureException(error)