From 5e0dba9012af93733c07ca143be2d32fa1befb15 Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Thu, 22 Dec 2022 17:40:18 -0500 Subject: [PATCH] [test262] Always return a pseudo Error object For unknown reasons I didn't have the energy to dig into, some Babel Error objects can't be written to so despite formatting the error message, the original one would still be used. To get around this I'm just constructing a fake object with a `name` and `message` so the correctly formatted messages are used. --- compiler/forget/scripts/test262-preprocessor.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/compiler/forget/scripts/test262-preprocessor.js b/compiler/forget/scripts/test262-preprocessor.js index 25571ec7e0..e42fce7f4b 100644 --- a/compiler/forget/scripts/test262-preprocessor.js +++ b/compiler/forget/scripts/test262-preprocessor.js @@ -16,13 +16,19 @@ module.exports = (test) => { } } catch (error) { // We use the `stderr` output to group errors so we can count them, so we need to dedupe errors - // that are the same but differ slightly - error.message = error.message.replace(/ \(\d+:\d+\)/, ""); // some errors report line numbers - error.message = error.message.replace(/\/.*\.js:\s/, ""); // babel seems to output filenames + // that are the same but differ slightly. + let { name, message } = error; + message = message.replace(/\/.*\.js:\s/, ""); // babel seems to output filenames + message = message.split(/\(\d+:\d+\)/)[0]; // some errors report line numbers and codeframes + message = message.trim(); + + // For unknown reasons I don't have the energy to dig into some Babel error instances can't be + // written to, so we construct a psedudo object here so the correctly formatted error messages + // are emitted test.result = { - stderr: `${error.name}: ${error.message}\n`, + stderr: `${name}: ${message}\n`, stdout: "", - error, + error: { name, message }, }; }