Skip to content

Commit

Permalink
Added uncaught exception handler + electron version bump
Browse files Browse the repository at this point in the history
Fixes #389 hopefully
  • Loading branch information
RvanderLaan committed Dec 5, 2021
1 parent 2a5f374 commit db61682
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"@typescript-eslint/eslint-plugin": "^4.2.0",
"@typescript-eslint/parser": "^4.2.0",
"css-loader": "^5.2.0",
"electron": "15.0.0",
"electron": "^15.3.3",
"electron-builder": "^22.10.5",
"eslint": "^7.18.0",
"eslint-config-prettier": "^8.1.0",
Expand Down
35 changes: 35 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,41 @@ autoUpdater.on('download-progress', (progressObj: { percent: number }) => {
mainWindow.setProgressBar(progressObj.percent / 100);
});

// Handling uncaught exceptions:
process.on('uncaughtException', async (error) => {
console.error('Uncaught exception', error);

const errorMessage = `An unexpected error occurred. Please file a bug report if you think this needs fixing!\n${
error?.stack?.includes(error.message) ? '' : `${error.name}: ${error.message.slice(0, 200)}\n`
}\n${error.stack?.slice(0, 300)}`;

try {
if (mainWindow != null && !mainWindow.isDestroyed()) {
// Show a dialog prompting the user to either restart, continue on or quit
const dialogResult = await dialog.showMessageBox(mainWindow, {
type: 'error',
title: 'Unexpected error',
message: errorMessage,
buttons: ['Restart Allusion', 'Quit Allusion', 'Try to keep running'],
});
if (dialogResult.response === 0) {
forceRelaunch(); // Restart
} else if (dialogResult.response === 1) {
app.exit(0); // Quit
} else if (dialogResult.response === 2) {
// Keep running
}
} else {
// No main window, show a fallback dialog
dialog.showErrorBox('Unexpected error', errorMessage);
app.exit(1);
}
} catch (e) {
console.error('Could not show error dialog', e);
process.exit(1);
}
});

//---------------------------------------------------------------------------------//
// Messaging: Sending and receiving messages between the main and renderer process //
//---------------------------------------------------------------------------------//
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3303,10 +3303,10 @@ electron-updater@^4.3.8:
lodash.isequal "^4.5.0"
semver "^7.3.4"

electron@15.0.0:
version "15.0.0"
resolved "https://registry.yarnpkg.com/electron/-/electron-15.0.0.tgz#b1b6244b1cffddf348c27c54b1310b3a3680246e"
integrity sha512-LlBjN5nCJoC7EDrgfDQwEGSGSAo/o08nSP5uJxN2m+ZtNA69SxpnWv4yPgo1K08X/iQPoGhoZu6C8LYYlk1Dtg==
electron@^15.3.3:
version "15.3.3"
resolved "https://registry.yarnpkg.com/electron/-/electron-15.3.3.tgz#e66c6c6fbcd74641dbfafe5e101228d2b7734c7b"
integrity sha512-tr4UaMosN6+s8vSbx6OxqRXDTTCBjjJkmDMv0b0sg8f+cRFQeY0u7xYbULpXS4B1+hHJmdh7Nz40Qpv0bJXa6w==
dependencies:
"@electron/get" "^1.13.0"
"@types/node" "^14.6.2"
Expand Down

0 comments on commit db61682

Please sign in to comment.