Skip to content

Commit bc59bcb

Browse files
committed
Handle all errors globally and broadcast
1 parent b410345 commit bc59bcb

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/app/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ ipc.once('app:launched', function() {
5858

5959
var debug = require('debug')('mongodb-compass:app');
6060

61+
window.addEventListener('error', (event) => {
62+
event.preventDefault();
63+
ipc.call('compass:error:fatal', { message: event.error.message, stack: event.error.stack });
64+
});
65+
6166
/**
6267
* The top-level application singleton that brings everything together!
6368
*/
@@ -130,6 +135,7 @@ var Application = View.extend({
130135
console.error('Fatal Error!: ', id, err);
131136
const metrics = require('mongodb-js-metrics')();
132137
metrics.error(err);
138+
ipc.call('compass:error:fatal', { message: err.message, stack: err.stack });
133139
const StatusAction = app.appRegistry.getAction('Status.Actions');
134140
StatusAction.setMessage(err);
135141
},

src/app/loading/loading.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ ipc.on(CHANGE_STATUS, (evt, meta) => {
2525
globalAppRegistry.emit(CHANGE_STATUS, meta);
2626
});
2727

28+
ipc.on('compass:error:fatal', (evt, meta) => {
29+
console.error(meta.stack);
30+
});
31+
2832
const loadingStore = configureStore({
2933
globalAppRegistry: globalAppRegistry
3034
});

src/main/window-manager.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ var createWindow = (module.exports.create = function(opts) {
170170
ipc.broadcast('compass:loading:change-status', meta);
171171
});
172172

173+
ipc.respondTo('compass:error:fatal', (evt, meta) => {
174+
ipc.broadcast('compass:error:fatal', meta);
175+
});
176+
173177
/**
174178
* `closed` is always fired if the `BrowserWindow`
175179
* is explicity `destroy()`ed when `_window` is ready

0 commit comments

Comments
 (0)