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

@@ -146,6 +146,7 @@
"electron-log": "^5.2.3",
"electron-settings": "^4.0.4",
"electron-squirrel-startup": "^1.0.1",
"electron-unhandled": "^5.0.0",
"ffmpeg-static": "^5.2.0",
"file-type": "^19.6.0",
"fluent-ffmpeg": "^2.1.3",
@@ -166,6 +167,7 @@
"microsoft-cognitiveservices-speech-sdk": "^1.41.0",
"mime-types": "^2.1.35",
"mustache": "^4.2.0",
"new-github-issue-url": "^1.0.0",
"next-themes": "^0.4.3",
"openai": "^4.73.1",
"pitchfinder": "^2.3.2",

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