From a0d96d5a74b2bec4ce37239154bf9873d612bb3a Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Mon, 30 Jun 2025 17:34:55 +0200 Subject: [PATCH] Do not swallow original error stack trace in box.js --- box.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/box.js b/box.js index 4f51b9a77..6fd723a7b 100755 --- a/box.js +++ b/box.js @@ -35,6 +35,7 @@ async function setupNetworking() { // this is also used as the 'uncaughtException' handler which can only have synchronous functions function exitSync(status) { const ts = new Date().toISOString(); + if (status.message) fs.write(logFd, `${ts} ${status.message}\n`, function () {}); const msg = status.error.stack.replace(/\n/g, `\n${ts} `); // prefix each line with ts if (status.error) fs.write(logFd, `${ts} ${msg}\n`, function () {}); fs.fsyncSync(logFd); @@ -55,7 +56,7 @@ async function startServers() { async function main() { const [error] = await safe(startServers()); - if (error) return exitSync({ error: new Error(`Error starting server: ${error.message}`), code: 1 }); + if (error) return exitSync({ error, code: 1, message: 'Error starting servers' }); // require this here so that logging handler is already setup const debug = require('debug')('box:box'); @@ -96,7 +97,7 @@ async function main() { }, 2000); // need to wait for the task processes to die }); - process.on('uncaughtException', (error) => exitSync({ error, code: 1 })); + process.on('uncaughtException', (error) => exitSync({ error, code: 1, message: 'From uncaughtException handler.' })); } main();