Commit f22b922f authored by Andy Wermke's avatar Andy Wermke Committed by GitHub

Try to report all unhandled errors in workers (#126)

parent 0372c1c3
......@@ -151,9 +151,29 @@ export function expose(exposed: WorkerFunction | WorkerModule<any>) {
}
}
if (typeof self !== "undefined" && typeof self.addEventListener === "function") {
self.addEventListener("error", event => {
// Post with some delay, so the master had some time to subscribe to messages
setTimeout(() => postUncaughtErrorMessage(event.error), 250)
})
self.addEventListener("unhandledrejection", event => {
const error = (event as any).reason
if (error && typeof (error as any).message === "string") {
// Post with some delay, so the master had some time to subscribe to messages
setTimeout(() => postUncaughtErrorMessage(error), 250)
}
})
}
if (typeof process !== "undefined") {
process.on("uncaughtException", (error) => {
// Post with some delay, so the master had some time to subscribe to messages
setTimeout(() => postUncaughtErrorMessage(error), 250)
})
process.on("unhandledRejection", (error) => {
if (error && typeof (error as any).message === "string") {
// Post with some delay, so the master had some time to subscribe to messages
setTimeout(() => postUncaughtErrorMessage(error as any), 250)
}
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment