Do not swallow original error stack trace in box.js

This commit is contained in:
Johannes Zellner
2025-06-30 17:34:55 +02:00
parent 0c8620e944
commit a0d96d5a74
+3 -2
View File
@@ -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();