-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { app, dialog, clipboard } from 'electron'; | ||
import cleanStack from 'clean-stack'; | ||
import ensureError from 'ensure-error'; | ||
import COMPASS_ICON from './icon'; | ||
|
||
async function handleUnhandledRejection(err: Error): Promise<void> { | ||
// eslint-disable-next-line no-console | ||
console.error('handling unhandledRejection', err); | ||
err = ensureError(err); | ||
const stack = cleanStack(err.stack || ''); | ||
|
||
const detail = `${app.getName()} version ${app.getVersion()}\nStacktrace:\n${stack}`; | ||
const message = `${app.getName()} has encountered an unexpected error`; | ||
|
||
// eslint-disable-next-line no-console | ||
console.error(`${message}: ${detail}`); | ||
|
||
const showErrorMessageBox = async () => { | ||
const { response } = await dialog.showMessageBox({ | ||
type: 'error', | ||
buttons: [ | ||
'OK', | ||
process.platform === 'darwin' ? 'Copy Error' : 'Copy error', | ||
], | ||
icon: COMPASS_ICON, | ||
defaultId: 0, | ||
noLink: true, | ||
message: message, | ||
detail: detail, | ||
}); | ||
|
||
if (response === 1) { | ||
clipboard.writeText(`${message}\n${stack}`); | ||
return; | ||
} | ||
|
||
if (response === 0) { | ||
app.quit(); | ||
return; | ||
} | ||
}; | ||
|
||
// Dialog can't be used until app emits a `ready` event | ||
await app.whenReady(); | ||
await showErrorMessageBox(); | ||
} | ||
|
||
export { handleUnhandledRejection }; |
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