From 3c93f73b2d412007253ba9b1ee5da2ec25ed2954 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Tue, 3 Jan 2023 12:58:42 +0100 Subject: [PATCH] refactor: better error logging (#48903) * refactor: log full error, not .message and .stack * refactor: improve missing comments error message --- curriculum/test/test-challenges.js | 18 +++++++----------- .../translation-parser/index.js | 6 +++++- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/curriculum/test/test-challenges.js b/curriculum/test/test-challenges.js index b5099067fac..032993238b2 100644 --- a/curriculum/test/test-challenges.js +++ b/curriculum/test/test-challenges.js @@ -70,29 +70,25 @@ const commentExtractors = { const { flatten, isEmpty, cloneDeep, isEqual } = lodash; -// rethrow unhandled rejections to make sure the tests exit with -1 +// rethrow unhandled rejections to make sure the tests exit with non-zero code process.on('unhandledRejection', err => handleRejection(err)); // If an uncaught exception gets here, then mocha is in an unexpected state. All // we can do is log the exception and exit with a non-zero code. process.on('uncaughtException', err => { - console.error('Uncaught exception:', err.message); - console.error(err.stack); - // eslint-disable-next-line no-process-exit + console.error('Uncaught exception:'); + console.error(err); process.exit(1); }); +// some errors *may* not be reported, since cleanup is triggered by the first +// error and that starts shutting down the browser and the server. const handleRejection = err => { // setting the error code because node does not (yet) exit with a non-zero // code on unhandled exceptions. process.exitCode = 1; cleanup(); - if (process.env.FULL_OUTPUT === 'true') { - // some errors *may* not be reported, since cleanup is triggered by the - // first error and that starts shutting down the browser and the server. - console.error(err); - } else { - throw err; - } + console.error(err); + if (process.env.FULL_OUTPUT !== 'true') process.exit(); }; const dom = new jsdom.JSDOM(''); diff --git a/tools/challenge-parser/translation-parser/index.js b/tools/challenge-parser/translation-parser/index.js index 841272650dc..ea418e17792 100644 --- a/tools/challenge-parser/translation-parser/index.js +++ b/tools/challenge-parser/translation-parser/index.js @@ -100,7 +100,11 @@ function translateGeneric( updateCounts(commentCounts, dict[comment][lang]); text = text.replace(match, `${before}${dict[comment][lang]}${after}`); } else if (comment.trim()) { - throw `${comment} does not appear in the comment dictionary`; + throw `The comment +${comment} +does not appear in the comment dictionary. +When updating or adding a comment it must have the same text in the English challenges and the comment dictionary. +`; } }