From d319132135099b7a622d62f879a82eea94a15ad8 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Mon, 22 Feb 2016 18:45:49 +0100 Subject: [PATCH] Avoid exceptions when serial break or overruns occur without `info` object. --- js/serial.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/js/serial.js b/js/serial.js index 03b0adf5..ff432d1e 100644 --- a/js/serial.js +++ b/js/serial.js @@ -77,21 +77,23 @@ var serial = { setTimeout(function() { chrome.serial.setPaused(info.connectionId, false, function() { self.getInfo(function (info) { - if (info.paused) { - // assume unrecoverable, disconnect - console.log('SERIAL: Connection did not recover from ' + self.error + ' condition, disconnecting'); - GUI.log('Unrecoverable failure of serial connection, disconnecting...'); - googleAnalytics.sendException('Serial: ' + self.error + ' - unrecoverable', false); - - if (GUI.connected_to || GUI.connecting_to) { - $('a.connect').click(); - } else { - self.disconnect(); + if (info) { + if (info.paused) { + // assume unrecoverable, disconnect + console.log('SERIAL: Connection did not recover from ' + self.error + ' condition, disconnecting'); + GUI.log('Unrecoverable failure of serial connection, disconnecting...'); + googleAnalytics.sendException('Serial: ' + self.error + ' - unrecoverable', false); + + if (GUI.connected_to || GUI.connecting_to) { + $('a.connect').click(); + } else { + self.disconnect(); + } + } + else { + console.log('SERIAL: Connection recovered from ' + self.error + ' condition'); + googleAnalytics.sendException('Serial: ' + self.error + ' - recovered', false); } - } - else { - console.log('SERIAL: Connection recovered from ' + self.error + ' condition'); - googleAnalytics.sendException('Serial: ' + self.error + ' - recovered', false); } }); });