Skip to content

Commit e3420a4

Browse files
authored
Fix build script errors (#15493)
There is a SES bug that results in errors being printed to the console as `{}`[1]. The known workaround is to print the error stack rather than printing the error directly. This affects our build script when it is run with LavaMoat. We used this workaround in one place in the build script already, but not in the handler for task errors. We now use it in both places. The workaround has been moved to a function that we can use throughout the build script. [1]: endojs/endo#944
1 parent 42c8703 commit e3420a4

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

development/build/scripts.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const metamaskrc = {
6363
const { streamFlatMap } = require('../stream-flat-map');
6464
const { BuildType } = require('../lib/build-type');
6565
const { BUILD_TARGETS } = require('./constants');
66+
const { logError } = require('./utils');
6667

6768
const {
6869
createTask,
@@ -1053,7 +1054,7 @@ async function createBundle(buildConfiguration, { reloadOnChange }) {
10531054
if (!reloadOnChange) {
10541055
bundleStream.on('error', (error) => {
10551056
console.error('Bundling failed! See details below.');
1056-
console.error(error.stack || error);
1057+
logError(error);
10571058
process.exit(1);
10581059
});
10591060
}

development/build/task.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = {
1515
};
1616

1717
const { setupTaskDisplay } = require('./display');
18+
const { logError } = require('./utils');
1819

1920
async function runTask(taskName, { skipStats } = {}) {
2021
if (!(taskName in tasks)) {
@@ -30,7 +31,7 @@ async function runTask(taskName, { skipStats } = {}) {
3031
console.error(
3132
`MetaMask build: Encountered an error while running task "${taskName}".`,
3233
);
33-
console.error(err);
34+
logError(err);
3435
process.exit(1);
3536
}
3637
taskEvents.emit('complete');

development/build/utils.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ function getBrowserVersionMap(platforms, version) {
5151
}, {});
5252
}
5353

54+
/**
55+
* Log an error to the console.
56+
*
57+
* This function includes a workaround for a SES bug that results in errors
58+
* being printed to the console as `{}`. The workaround is to print the stack
59+
* instead, which does work correctly.
60+
*
61+
* @see {@link https://github.com/endojs/endo/issues/944}
62+
* @param {Error} error - The error to print
63+
*/
64+
function logError(error) {
65+
console.error(error.stack || error);
66+
}
67+
5468
module.exports = {
5569
getBrowserVersionMap,
70+
logError,
5671
};

0 commit comments

Comments
 (0)