From 283facdd31e1dc43fb457a97cdb8677d38e08bcf Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Tue, 17 Jun 2025 20:31:00 -0400 Subject: add workarounds for node-fetch crashes --- packages/backend/src/boot/entry.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'packages/backend/src/boot') diff --git a/packages/backend/src/boot/entry.ts b/packages/backend/src/boot/entry.ts index afb48e526c..af4a813833 100644 --- a/packages/backend/src/boot/entry.ts +++ b/packages/backend/src/boot/entry.ts @@ -63,14 +63,32 @@ async function main() { }); } + process.on('uncaughtException', (err) => { + // Workaround for https://github.com/node-fetch/node-fetch/issues/954 + if (String(err).match(/^TypeError: .+ is an? url with embedded credentials.$/)) { + console.debug('Suppressed node-fetch issue#954, but the current job may fail.'); + return; + } + + // Workaround for https://github.com/node-fetch/node-fetch/issues/1845 + if (String(err) === 'TypeError: Cannot read properties of undefined (reading \'body\')') { + console.debug('Suppressed node-fetch issue#1845, but the current job may fail.'); + return; + } + + // Throw all other errors to avoid inconsistent state. + // (per NodeJS docs, it's unsafe to suppress arbitrary errors in an uncaughtException handler.) + throw err; + }); + // Display detail of uncaught exception - process.on('uncaughtExceptionMonitor', ((err, origin) => { + process.on('uncaughtExceptionMonitor', (err, origin) => { try { logger.error(`Uncaught exception (${origin}):`, err); } catch { console.error(`Uncaught exception (${origin}):`, err); } - })); + }); // Dying away... process.on('disconnect', () => { -- cgit v1.2.3-freya From bf455c2f7a3122ab72bf7ef7498d758936b1db91 Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Mon, 7 Jul 2025 11:44:48 -0400 Subject: use logger instead of console for uncaughtException debug lines --- packages/backend/src/boot/entry.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/backend/src/boot') diff --git a/packages/backend/src/boot/entry.ts b/packages/backend/src/boot/entry.ts index af4a813833..530c75cc8e 100644 --- a/packages/backend/src/boot/entry.ts +++ b/packages/backend/src/boot/entry.ts @@ -66,13 +66,13 @@ async function main() { process.on('uncaughtException', (err) => { // Workaround for https://github.com/node-fetch/node-fetch/issues/954 if (String(err).match(/^TypeError: .+ is an? url with embedded credentials.$/)) { - console.debug('Suppressed node-fetch issue#954, but the current job may fail.'); + logger.debug('Suppressed node-fetch issue#954, but the current job may fail.'); return; } // Workaround for https://github.com/node-fetch/node-fetch/issues/1845 if (String(err) === 'TypeError: Cannot read properties of undefined (reading \'body\')') { - console.debug('Suppressed node-fetch issue#1845, but the current job may fail.'); + logger.debug('Suppressed node-fetch issue#1845, but the current job may fail.'); return; } -- cgit v1.2.3-freya From e8c71341237b21cde103c0c0a9a67647ba605bac Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Mon, 7 Jul 2025 11:45:01 -0400 Subject: remove unused console logging fallbacks --- packages/backend/src/boot/entry.ts | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) (limited to 'packages/backend/src/boot') diff --git a/packages/backend/src/boot/entry.ts b/packages/backend/src/boot/entry.ts index 530c75cc8e..bbe6a57383 100644 --- a/packages/backend/src/boot/entry.ts +++ b/packages/backend/src/boot/entry.ts @@ -55,11 +55,7 @@ async function main() { // Display detail of unhandled promise rejection if (!envOption.quiet) { process.on('unhandledRejection', e => { - try { - logger.error('Unhandled rejection:', inspect(e)); - } catch { - console.error('Unhandled rejection:', inspect(e)); - } + logger.error('Unhandled rejection:', inspect(e)); }); } @@ -83,34 +79,18 @@ async function main() { // Display detail of uncaught exception process.on('uncaughtExceptionMonitor', (err, origin) => { - try { - logger.error(`Uncaught exception (${origin}):`, err); - } catch { - console.error(`Uncaught exception (${origin}):`, err); - } + logger.error(`Uncaught exception (${origin}):`, err); }); // Dying away... process.on('disconnect', () => { - try { - logger.warn('IPC channel disconnected! The process may soon die.'); - } catch { - console.warn('IPC channel disconnected! The process may soon die.'); - } + logger.warn('IPC channel disconnected! The process may soon die.'); }); process.on('beforeExit', code => { - try { - logger.warn(`Event loop died! Process will exit with code ${code}.`); - } catch { - console.warn(`Event loop died! Process will exit with code ${code}.`); - } + logger.warn(`Event loop died! Process will exit with code ${code}.`); }); process.on('exit', code => { - try { - logger.info(`The process is going to exit with code ${code}`); - } catch { - console.info(`The process is going to exit with code ${code}`); - } + logger.info(`The process is going to exit with code ${code}`); }); //#endregion -- cgit v1.2.3-freya