From 6bdaada689dc9e78c461e4158310d99faa54347f Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 14 Sep 2020 15:56:08 -0500 Subject: [PATCH] Move uncaught exception handler to wrapper Feels more appropriate there to me. --- src/node/entry.ts | 7 ------- src/node/wrapper.ts | 8 ++++++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/node/entry.ts b/src/node/entry.ts index 5869ae46..dfd78cda 100644 --- a/src/node/entry.ts +++ b/src/node/entry.ts @@ -18,13 +18,6 @@ import { loadPlugins } from "./plugin" import { generateCertificate, hash, humanPath, open } from "./util" import { ipcMain, wrap } from "./wrapper" -process.on("uncaughtException", (error) => { - logger.error(`Uncaught exception: ${error.message}`) - if (typeof error.stack !== "undefined") { - logger.error(error.stack) - } -}) - let pkg: { version?: string; commit?: string } = {} try { pkg = require("../../package.json") diff --git a/src/node/wrapper.ts b/src/node/wrapper.ts index ba459efd..2f1eb037 100644 --- a/src/node/wrapper.ts +++ b/src/node/wrapper.ts @@ -254,6 +254,14 @@ if (!process.stdout.isTTY) { process.stdout.on("error", () => ipcMain().exit()) } +// Don't let uncaught exceptions crash the process. +process.on("uncaughtException", (error) => { + logger.error(`Uncaught exception: ${error.message}`) + if (typeof error.stack !== "undefined") { + logger.error(error.stack) + } +}) + export const wrap = (fn: () => Promise): void => { if (ipcMain().parentPid) { ipcMain()