Skip to content

Commit 39e9ed1

Browse files
committed
feat: initial unhandled rejections tracking for workerd
Still misses delayed hanging setTimeout, but otherwise seems robust
1 parent f8dccbb commit 39e9ed1

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

bundler/modules/globals.cjs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,17 @@ This activity created errors and would have caused tests to fail, but instead tr
332332
// Cancelling the default behavior is less robust as we want to treat this as error
333333
globalThis.addEventListener('unhandledrejection', () => logHeader())
334334
} else if (process.env.EXODUS_TEST_PLATFORM === 'workerd') {
335-
// We can't enable this yet, it misfires a lot. See https://github.com/cloudflare/workerd/issues/6020
336-
/*
337-
globalThis.addEventListener('unhandledrejection', ({ reason }) => {
338-
logHeader()
339-
print(`Uncaught error: ${reason}`)
335+
// See https://github.com/cloudflare/workerd/issues/6020
336+
const rejections = new Map()
337+
globalThis.addEventListener('rejectionhandled', (e) => clearTimeout(rejections.get(e.promise)))
338+
globalThis.addEventListener('unhandledrejection', (e) => {
339+
const timeout = setTimeout(() => {
340+
rejections.delete(e.promise)
341+
logHeader()
342+
print(`Uncaught error: ${e.reason}`)
343+
}, 0)
344+
rejections.set(e.promise, timeout)
340345
})
341-
*/
342346
}
343347
}
344348

0 commit comments

Comments
 (0)