Show dialog if application fails to start up properly
parent
ec12733dad
commit
68af1ae1ea
@ -1,16 +1,43 @@
|
||||
const addUnhandledErrorHandler = require('electron-unhandled');
|
||||
const electron = require('electron');
|
||||
|
||||
const Errors = require('../js/modules/types/errors');
|
||||
|
||||
// addHandler :: Unit -> Unit
|
||||
const { app, dialog, clipboard } = electron;
|
||||
|
||||
// We're using hard-coded strings in this file because it needs to be ready
|
||||
// to report errors before we do anything in the app. Also, we expect users to directly
|
||||
// paste this text into search engines to find the bugs on GitHub.
|
||||
|
||||
function handleError(prefix, error) {
|
||||
console.error(`${prefix}:`, Errors.toLogFormat(error));
|
||||
|
||||
if (app.isReady()) {
|
||||
// title field is not shown on macOS, so we don't use it
|
||||
const buttonIndex = dialog.showMessageBox({
|
||||
buttons: ['OK', 'Copy error'],
|
||||
defaultId: 0,
|
||||
detail: error.stack,
|
||||
message: prefix,
|
||||
noLink: true,
|
||||
type: 'error',
|
||||
});
|
||||
|
||||
if (buttonIndex === 1) {
|
||||
clipboard.writeText(`${prefix}\n${error.stack}`);
|
||||
}
|
||||
} else {
|
||||
dialog.showErrorBox(prefix, error.stack);
|
||||
}
|
||||
|
||||
app.quit();
|
||||
}
|
||||
|
||||
exports.addHandler = () => {
|
||||
addUnhandledErrorHandler({
|
||||
logger: error => {
|
||||
console.error(
|
||||
'Uncaught error or unhandled promise rejection:',
|
||||
Errors.toLogFormat(error)
|
||||
);
|
||||
},
|
||||
showDialog: false,
|
||||
process.on('uncaughtException', error => {
|
||||
handleError('Unhandled Error', error);
|
||||
});
|
||||
|
||||
process.on('unhandledRejection', error => {
|
||||
handleError('Unhandled Promise Rejection', error);
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue