handle unhandle exception/rejection in process level (#1210)

This commit is contained in:
an-lee
2024-11-27 09:53:38 +08:00
committed by GitHub
parent 0ff0025747
commit f0e7fd7c38
3 changed files with 110 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
import { app, BrowserWindow, protocol, net } from "electron";
import { app, BrowserWindow, protocol, net, shell } from "electron";
import path from "path";
import fs from "fs-extra";
import settings from "@main/settings";
@@ -8,6 +8,8 @@ import ElectronSquirrelStartup from "electron-squirrel-startup";
import contextMenu from "electron-context-menu";
import { t } from "i18next";
import { updateElectronApp, UpdateSourceType } from "update-electron-app";
import unhandled from "electron-unhandled";
import newGithubIssueUrl from "new-github-issue-url";
const logger = log.scope("main");
@@ -133,6 +135,43 @@ app.on("ready", async () => {
});
mainWindow.init();
unhandled({
showDialog: true,
logger: logger.error,
reportButton: (error) => {
const url = newGithubIssueUrl({
user: "ZuodaoTech",
repo: "everyone-can-use-english",
title: "Unhandled Error",
body: `
## Node.js error stack
**Message:**
\`\`\`
${error.message}
\`\`\`
**Stack:**
\`\`\`
${error.stack}
\`\`\`
**Environment:**
\`\`\`
${app.name} ${app.getVersion()}
Electron ${process.versions.electron}
${process.platform} ${process.arch}
Locale: ${app.getLocale()}
\`\`\``,
});
shell.openExternal(url);
},
});
});
// Quit when all windows are closed, except on macOS. There, it's common