From 25cbe6c91bc84f9cae3420e480020aba6de96dbe Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Mon, 25 Sep 2023 16:31:37 -0700 Subject: [PATCH 1/2] Add more diagnostic error handling in string extraction. --- packages/kolibri-tools/lib/i18n/astUtils.js | 44 ++++++++++++++------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/packages/kolibri-tools/lib/i18n/astUtils.js b/packages/kolibri-tools/lib/i18n/astUtils.js index 8bf305d3f69..308e1d84c86 100644 --- a/packages/kolibri-tools/lib/i18n/astUtils.js +++ b/packages/kolibri-tools/lib/i18n/astUtils.js @@ -140,23 +140,33 @@ function getObjectifiedValue(nodePropertyValue) { n => n.key.name === 'message' ); + if (!messageNode) { + // This is mostly for dev debugging. If this happens then somethings wrong enough that + // we should let the user know and just bail for now until it gets worked out + throw new ReferenceError( + 'Trying to get the message from an object in $trs but did not find a `message` key.\n' + + 'Available keys on the message object include:\n' + + get(nodePropertyValue, 'properties', []) + .map(p => p.key.name) + .join(', ') + ); + } + message = stringFromAnyLiteral(messageNode); try { context = stringFromAnyLiteral(contextNode); } catch (e) { context = ''; } - - if (!message) { - // This is mostly for dev debugging. If this happens then somethings wrong enough that - // we should let the user know and just bail for now until it gets worked out - logging.error( - 'Trying to get the message from an object in $trs but did not find a `message` key.\n\n', - 'The above error is unrecoverable (✖╭╮✖). This indicates a bug that needs fixing. Sorry.' - ); - logging.error(nodePropertyValue.properties[0].value.value); - process.exit(1); - } + } + if (!message) { + // This is mostly for dev debugging. If this happens then somethings wrong enough that + // we should let the user know and just bail for now until it gets worked out + throw new ReferenceError( + 'Trying to get the message from an object in $trs but did not find a `message` key.\n\n' + + 'The above error is unrecoverable (✖╭╮✖). This indicates a bug that needs fixing. Sorry.' + + nodePropertyValue.properties[0].value.value + ); } return { message, context: `${CONTEXT_LINE}${context}` }; } @@ -351,9 +361,15 @@ function generateMessagesFromASTNode(messageNodeProperties, messageNamespace, as if (messageNodeProperties && messageNamespace) { // Now that we have the properties we care about, let's do the thing we're here to do! for (const $trProperty of messageNodeProperties) { - results[ - `${messageNamespace}.${getPropertyKey($trProperty, ast, filePath)}` - ] = getObjectifiedValue($trProperty.value); + const messageId = `${messageNamespace}.${getPropertyKey($trProperty, ast, filePath)}`; + try { + results[messageId] = getObjectifiedValue($trProperty.value); + } catch (e) { + logging.error('Issue in file: ', filePath); + logging.error('Could not extract message from: ', messageId); + logging.error(e); + process.exit(1); + } } } return results; From ff0b47db06e482d900ea5c56491ccb6d87227ded Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Mon, 25 Sep 2023 16:32:27 -0700 Subject: [PATCH 2/2] Fix incorrectly labelled message key. --- .../kolibri-common/strings/enhancedQuizManagementStrings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kolibri-common/strings/enhancedQuizManagementStrings.js b/packages/kolibri-common/strings/enhancedQuizManagementStrings.js index 0dd11b384e7..1461805ce54 100644 --- a/packages/kolibri-common/strings/enhancedQuizManagementStrings.js +++ b/packages/kolibri-common/strings/enhancedQuizManagementStrings.js @@ -44,7 +44,7 @@ export const enhancedQuizManagementStrings = createTranslator('EnhancedQuizManag message: 'Quiz resource selection', }, selectResourcesFromChannels: { - messages: 'Select resources from channels', + message: 'Select resources from channels', }, sectionOrder: { message: 'Section order',