On database error: show popup, allow user to delete and relaunch
This commit is contained in:
parent
3fb6ab295f
commit
5165eb3bd4
5 changed files with 87 additions and 12 deletions
|
@ -5,9 +5,9 @@ const Errors = require('../js/modules/types/errors');
|
|||
const { app, dialog, clipboard } = electron;
|
||||
const { redactAll } = require('../js/modules/privacy');
|
||||
|
||||
// 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.
|
||||
// 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';
|
||||
|
||||
function handleError(prefix, error) {
|
||||
console.error(`${prefix}:`, Errors.toLogFormat(error));
|
||||
|
@ -15,24 +15,29 @@ function handleError(prefix, 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'],
|
||||
buttons: [quitText, copyErrorAndQuitText],
|
||||
defaultId: 0,
|
||||
detail: error.stack,
|
||||
detail: redactAll(error.stack),
|
||||
message: prefix,
|
||||
noLink: true,
|
||||
type: 'error',
|
||||
});
|
||||
|
||||
if (buttonIndex === 1) {
|
||||
clipboard.writeText(`${prefix}\n${redactAll(error.stack)}`);
|
||||
clipboard.writeText(`${prefix}\n\n${redactAll(error.stack)}`);
|
||||
}
|
||||
} else {
|
||||
dialog.showErrorBox(prefix, error.stack);
|
||||
}
|
||||
|
||||
app.quit();
|
||||
app.exit(1);
|
||||
}
|
||||
|
||||
exports.updateLocale = messages => {
|
||||
quitText = messages.quit.message;
|
||||
copyErrorAndQuitText = messages.copyErrorAndQuit.message;
|
||||
};
|
||||
|
||||
exports.addHandler = () => {
|
||||
process.on('uncaughtException', error => {
|
||||
handleError('Unhandled Error', error);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue