1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

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.
This commit is contained in:
Mark Stacey 2020-07-29 13:09:52 -03:00 committed by GitHub
parent 1582855e28
commit b7715f6e70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)