Skip to content

Commit

Permalink
Improve error handling (wulkano#837)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
karaggeorge and sindresorhus authored Apr 29, 2020
1 parent 144077b commit f2ad4f0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
3 changes: 2 additions & 1 deletion main/common/aperture.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const callPlugins = async method => Promise.all(recordingPlugins.map(async ({plu
})
);
} catch (error) {
showError(error);
showError(error, {title: `Something went wrong while using the plugin “${plugin.prettyName}”`});
}
}
}));
Expand Down Expand Up @@ -141,6 +141,7 @@ const startRecording = async options => {
track('recording/stopped/error');
showError(error, {title: 'Recording error', reportToSentry: true});
past = null;
cleanup();
return;
}

Expand Down
21 changes: 18 additions & 3 deletions main/utils/errors.js
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};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"aperture": "^5.2.0",
"base64-img": "^1.0.4",
"classnames": "^2.2.6",
"clean-stack": "^2.2.0",
"delay": "^4.3.0",
"electron-better-ipc": "^0.8.0",
"electron-log": "^4.1.0",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2529,6 +2529,11 @@ clean-regexp@^1.0.0:
dependencies:
escape-string-regexp "^1.0.5"

clean-stack@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b"
integrity sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==

cli-boxes@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/cli-boxes/-/cli-boxes-2.2.0.tgz#538ecae8f9c6ca508e3c3c95b453fe93cb4c168d"
Expand Down

0 comments on commit f2ad4f0

Please sign in to comment.