mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-23 23:54:13 +08:00
fix(error): send all renderer errors to the browser process
This commit is contained in:
parent
345d006533
commit
140f4f34ec
2 changed files with 31 additions and 3 deletions
|
@ -546,6 +546,14 @@ export default class Application extends EventEmitter {
|
||||||
sourceWindow.webContents.send('remote-run-results', params);
|
sourceWindow.webContents.send('remote-run-results', params);
|
||||||
delete this._sourceWindows[params.taskId];
|
delete this._sourceWindows[params.taskId];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMain.on("report-error", (event, params = {}) => {
|
||||||
|
const errorParams = JSON.parse(params.errorJSON || "");
|
||||||
|
let err = new Error();
|
||||||
|
err = Object.assign(err, errorParams);
|
||||||
|
global.errorLogger.reportError(err, params.extra)
|
||||||
|
event.returnValue = true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public: Executes the given command.
|
// Public: Executes the given command.
|
||||||
|
|
|
@ -6,7 +6,9 @@ var ErrorLogger, _, fs, path, app, os, remote;
|
||||||
os = require('os');
|
os = require('os');
|
||||||
fs = require('fs-plus');
|
fs = require('fs-plus');
|
||||||
path = require('path');
|
path = require('path');
|
||||||
|
ipcRenderer = null;
|
||||||
if (process.type === 'renderer') {
|
if (process.type === 'renderer') {
|
||||||
|
ipcRenderer = require('electron').ipcRenderer;
|
||||||
remote = require('electron').remote;
|
remote = require('electron').remote;
|
||||||
app = remote.app;
|
app = remote.app;
|
||||||
} else {
|
} else {
|
||||||
|
@ -54,12 +56,30 @@ module.exports = ErrorLogger = (function() {
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ErrorLogger.prototype.reportError = function(error, extra) {
|
ErrorLogger.prototype.reportError = function(error, extra) {
|
||||||
var nslog = require('nslog');
|
|
||||||
if (!error) { error = {stack: ""} }
|
if (!error) { error = {stack: ""} }
|
||||||
this._appendLog(error.stack)
|
this._appendLog(error.stack)
|
||||||
if (extra) { this._appendLog(extra) }
|
if (extra) { this._appendLog(extra) }
|
||||||
this._notifyExtensions("reportError", error, extra)
|
if (process.type === "renderer") {
|
||||||
if (process.type === 'browser') { nslog(error.stack) }
|
var errorJSON = JSON.stringify(error);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We synchronously send all errors to the backend main process.
|
||||||
|
*
|
||||||
|
* This is important because errors can frequently happen right
|
||||||
|
* before a renderer window is closing. Since error reporting hits
|
||||||
|
* APIs and is asynchronous it's possible for the window to be
|
||||||
|
* destroyed before the report makes it.
|
||||||
|
*
|
||||||
|
* This is a rare use of `sendSync` to ensure the command has made
|
||||||
|
* it before the window closes.
|
||||||
|
*/
|
||||||
|
ipcRenderer.sendSync("report-error", {errorJSON: errorJSON, extra: extra})
|
||||||
|
|
||||||
|
} else {
|
||||||
|
var nslog = require('nslog');
|
||||||
|
this._notifyExtensions("reportError", error, extra)
|
||||||
|
nslog(error.stack)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorLogger.prototype.openLogs = function() {
|
ErrorLogger.prototype.openLogs = function() {
|
||||||
|
|
Loading…
Reference in a new issue