From 7b46b7361cabc88e402e751464d74c442c818d0b Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Thu, 7 Sep 2023 17:01:47 +0200 Subject: [PATCH] :bug: Handle missing component translations more gracefully The exception-throwing approach breaks the open-forms E2E integration tests by crashing the form builder. --- src/components/builder/validate/i18n.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/builder/validate/i18n.tsx b/src/components/builder/validate/i18n.tsx index 1dabd111..c5dcf442 100644 --- a/src/components/builder/validate/i18n.tsx +++ b/src/components/builder/validate/i18n.tsx @@ -16,10 +16,11 @@ export function useManageValidatorsTranslations( // set any missing translations useEffect(() => { - if (!value) { - throw new Error('Missing default (Formik) value for `translatedErrors`!'); - } - const newValue = {...value}; + const newValue = value + ? {...value} + : (Object.fromEntries(supportedLanguageCodes.map(code => [code, {}])) as NonNullable< + S['translatedErrors'] + >); const emptyDefaults = Object.fromEntries(keys.map(k => [k, ''])); for (const code of supportedLanguageCodes) { newValue[code] = {...emptyDefaults, ...newValue[code]};