forked from wulkano/Kap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve error handling (wulkano#837)
Co-authored-by: Sindre Sorhus <[email protected]>
- Loading branch information
1 parent
144077b
commit f2ad4f0
Showing
4 changed files
with
26 additions
and
4 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
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,18 +1,33 @@ | ||
'use strict'; | ||
|
||
const {dialog} = require('electron'); | ||
const {dialog, clipboard} = require('electron'); | ||
const ensureError = require('ensure-error'); | ||
const Sentry = require('./sentry'); | ||
const cleanStack = require('clean-stack'); | ||
|
||
const showError = (error, {title, reportToSentry} = {}) => { | ||
const showError = async (error, {title, reportToSentry} = {}) => { | ||
const ensuredError = ensureError(error); | ||
const errorTitle = title || ensuredError.name; | ||
|
||
console.error(error); | ||
if (reportToSentry) { | ||
Sentry.captureException(ensuredError); | ||
} | ||
|
||
dialog.showErrorBox(title || ensuredError.name, ensuredError.stack); | ||
// This is not currently really async: https://github.com/electron/electron/issues/23319 | ||
const {response} = await dialog.showMessageBox({ | ||
type: 'error', | ||
message: errorTitle, | ||
detail: cleanStack(ensuredError.stack, {pretty: true}), | ||
buttons: [ | ||
'OK', | ||
'Copy Error' | ||
] | ||
}); | ||
|
||
if (response === 1) { | ||
clipboard.writeText(`${errorTitle}\n${cleanStack(ensuredError.stack)}`); | ||
} | ||
}; | ||
|
||
module.exports = {showError}; |
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