2018-11-17 00:49:59 +00:00
|
|
|
const electron = require('electron');
|
2018-03-06 17:05:53 +00:00
|
|
|
|
2018-07-21 19:00:08 +00:00
|
|
|
const Errors = require('../js/modules/types/errors');
|
2018-03-06 17:05:53 +00:00
|
|
|
|
2018-11-17 00:49:59 +00:00
|
|
|
const { app, dialog, clipboard } = electron;
|
2019-02-19 23:15:43 +00:00
|
|
|
const { redactAll } = require('../js/modules/privacy');
|
2018-11-17 00:49:59 +00:00
|
|
|
|
2019-02-20 01:32:44 +00:00
|
|
|
// We use hard-coded strings until we're able to update these strings from the locale.
|
|
|
|
let quitText = 'Quit';
|
|
|
|
let copyErrorAndQuitText = 'Copy error and quit';
|
2018-11-17 00:49:59 +00:00
|
|
|
|
|
|
|
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
|
2019-08-19 17:59:30 +00:00
|
|
|
const buttonIndex = dialog.showMessageBoxSync({
|
2019-02-20 01:32:44 +00:00
|
|
|
buttons: [quitText, copyErrorAndQuitText],
|
2018-11-17 00:49:59 +00:00
|
|
|
defaultId: 0,
|
2019-02-20 01:32:44 +00:00
|
|
|
detail: redactAll(error.stack),
|
2018-11-17 00:49:59 +00:00
|
|
|
message: prefix,
|
|
|
|
noLink: true,
|
|
|
|
type: 'error',
|
|
|
|
});
|
|
|
|
|
|
|
|
if (buttonIndex === 1) {
|
2019-02-20 01:32:44 +00:00
|
|
|
clipboard.writeText(`${prefix}\n\n${redactAll(error.stack)}`);
|
2018-11-17 00:49:59 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dialog.showErrorBox(prefix, error.stack);
|
|
|
|
}
|
|
|
|
|
2019-02-20 01:32:44 +00:00
|
|
|
app.exit(1);
|
2018-11-17 00:49:59 +00:00
|
|
|
}
|
|
|
|
|
2019-02-20 01:32:44 +00:00
|
|
|
exports.updateLocale = messages => {
|
|
|
|
quitText = messages.quit.message;
|
|
|
|
copyErrorAndQuitText = messages.copyErrorAndQuit.message;
|
|
|
|
};
|
|
|
|
|
2018-03-06 17:10:35 +00:00
|
|
|
exports.addHandler = () => {
|
2018-11-17 00:49:59 +00:00
|
|
|
process.on('uncaughtException', error => {
|
|
|
|
handleError('Unhandled Error', error);
|
|
|
|
});
|
|
|
|
|
|
|
|
process.on('unhandledRejection', error => {
|
|
|
|
handleError('Unhandled Promise Rejection', error);
|
2018-03-06 17:05:53 +00:00
|
|
|
});
|
|
|
|
};
|