diff options
context wiring - handle and log errors
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/background.js | 6 | ||||
-rw-r--r-- | app/scripts/contentscript.js | 6 | ||||
-rw-r--r-- | app/scripts/inpage.js | 3 | ||||
-rw-r--r-- | app/scripts/lib/port-stream.js | 9 |
4 files changed, 20 insertions, 4 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js index 6d9f4865d..0276124cc 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -76,7 +76,11 @@ function onRpcRequest(remotePort, payload){ zeroClient.sendAsync(payload, function onPayloadHandled(err, response){ if (err) throw err // console.log('MetaMaskPlugin - RPC complete:', payload, '->', response) - remotePort.postMessage(response) + try { + remotePort.postMessage(response) + } catch (_) { + // port disconnected + } }) } diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index 1b0de3375..105f24988 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -19,4 +19,8 @@ var pluginStream = new PortStream(pluginPort) // forward communication across pageStream.pipe(pluginStream) -pluginStream.pipe(pageStream)
\ No newline at end of file +pluginStream.pipe(pageStream) + +// log errors +pageStream.on('error', console.error.bind(console)) +pluginStream.on('error', console.error.bind(console))
\ No newline at end of file diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index 6bf75084c..001d9f4f9 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -12,6 +12,9 @@ var pluginStream = new LocalMessageDuplexStream({ var remoteProvider = new StreamProvider() remoteProvider.pipe(pluginStream).pipe(remoteProvider) +pluginStream.on('error', console.error.bind(console)) +remoteProvider.on('error', console.error.bind(console)) + // handle synchronous methods remotely // handle accounts cache diff --git a/app/scripts/lib/port-stream.js b/app/scripts/lib/port-stream.js index 7f3e8072e..8ff77ec4e 100644 --- a/app/scripts/lib/port-stream.js +++ b/app/scripts/lib/port-stream.js @@ -37,8 +37,13 @@ PortDuplexStream.prototype._read = noop PortDuplexStream.prototype._write = function(msg, encoding, cb){ // console.log('PortDuplexStream - sent message', msg) - this._port.postMessage(msg) - cb() + try { + this._port.postMessage(msg) + cb() + } catch(err){ + // this.emit('error', err) + cb(new Error('PortDuplexStream - disconnected')) + } } // util |