Skip to content

Commit 6bdaada

Browse files
committed
Move uncaught exception handler to wrapper
Feels more appropriate there to me.
1 parent 811cf33 commit 6bdaada

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/node/entry.ts

-7
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ import { loadPlugins } from "./plugin"
1818
import { generateCertificate, hash, humanPath, open } from "./util"
1919
import { ipcMain, wrap } from "./wrapper"
2020

21-
process.on("uncaughtException", (error) => {
22-
logger.error(`Uncaught exception: ${error.message}`)
23-
if (typeof error.stack !== "undefined") {
24-
logger.error(error.stack)
25-
}
26-
})
27-
2821
let pkg: { version?: string; commit?: string } = {}
2922
try {
3023
pkg = require("../../package.json")

src/node/wrapper.ts

+8
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,14 @@ if (!process.stdout.isTTY) {
254254
process.stdout.on("error", () => ipcMain().exit())
255255
}
256256

257+
// Don't let uncaught exceptions crash the process.
258+
process.on("uncaughtException", (error) => {
259+
logger.error(`Uncaught exception: ${error.message}`)
260+
if (typeof error.stack !== "undefined") {
261+
logger.error(error.stack)
262+
}
263+
})
264+
257265
export const wrap = (fn: () => Promise<void>): void => {
258266
if (ipcMain().parentPid) {
259267
ipcMain()

0 commit comments

Comments
 (0)