Display more information about remote event crashes.

If possible, we'll dig into the function args and print the ones that are attached remotely.
This commit is contained in:
Charlie Hess 2017-01-06 13:09:48 -08:00 committed by Kevin Sawicki
parent 8e39aea34a
commit 26e3ad3c2e

View file

@ -146,6 +146,28 @@ const throwRPCError = function (message) {
throw error
}
const rendererMissingErrorMessage = function (meta, args, callIntoRenderer) {
let message = `Attempting to call a function in a renderer window that has been closed or released.` +
`Function provided here: ${meta.location}.`;
if (!args || args.length === 0) return message;
if (!args[0].sender || !args[0].sender._events) return message;
const eventsAttached = args[0].sender._events;
const remoteEvents = Object.keys(eventsAttached).filter((eventName) => {
return Array.isArray(eventsAttached[eventName]) ?
eventsAttached[eventName].includes(callIntoRenderer) :
eventsAttached[eventName] === callIntoRenderer
});
if (remoteEvents && remoteEvents.length > 0) {
message += `\nRemote event names:`
remoteEvents.forEach((eventName) => message += ` ${eventName} `);
}
return message;
}
// Convert array of meta data from renderer into array of real values.
const unwrapArgs = function (sender, args) {
const metaToValue = function (meta) {
@ -196,7 +218,7 @@ const unwrapArgs = function (sender, args) {
if (!sender.isDestroyed() && webContentsId === sender.getId()) {
sender.send('ELECTRON_RENDERER_CALLBACK', meta.id, valueToMeta(sender, args))
} else {
throw new Error(`Attempting to call a function in a renderer window that has been closed or released. Function provided here: ${meta.location}.`)
throw new Error(rendererMissingErrorMessage(meta, args, callIntoRenderer));
}
}