-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show dialog if application fails to start up properly
- Loading branch information
1 parent
ec12733
commit 68af1ae
Showing
3 changed files
with
37 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters