handle remote exception (#12694)

* add cause property to exception in callFunction

* update exceptionToMeta function

* add sender argument
* and cause property to return value

* update exception convert in metaToValue function

* add from and cause properties to the exception error

* unit test for remote exception
This commit is contained in:
Tatsuya Hiroishi 2018-04-24 21:40:19 +09:00 committed by Shelley Vohr
parent 2579071b98
commit 9c65abd746
4 changed files with 54 additions and 17 deletions

View file

@ -206,7 +206,7 @@ function metaToValue (meta) {
promise: () => resolvePromise({then: metaToValue(meta.then)}),
error: () => metaToPlainObject(meta),
date: () => new Date(meta.value),
exception: () => { throw new Error(`${meta.message}\n${meta.stack}`) }
exception: () => { throw metaToException(meta) }
}
if (meta.type in types) {
@ -256,6 +256,15 @@ function metaToPlainObject (meta) {
return obj
}
// Construct an exception error from the meta.
function metaToException (meta) {
const error = new Error(`${meta.message}\n${meta.stack}`)
const remoteProcess = exports.process
error.from = remoteProcess ? remoteProcess.type : null
error.cause = metaToValue(meta.cause)
return error
}
// Browser calls a callback in renderer.
ipcRenderer.on('ELECTRON_RENDERER_CALLBACK', (event, id, args) => {
callbacksRegistry.apply(id, metaToValue(args))