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:
parent
8e39aea34a
commit
26e3ad3c2e
1 changed files with 23 additions and 1 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue