From 697943b512a52bd77aa4006643b62abba4312406 Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Sat, 28 Jan 2023 00:42:18 +0100 Subject: [PATCH] fix CheckRunTimeError (#3284) fic CheckRunTimeError --- src/js/serial.js | 15 ++++++++------- src/js/utils/common.js | 3 ++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/js/serial.js b/src/js/serial.js index 7ccbd3055f..009ceb6dcb 100644 --- a/src/js/serial.js +++ b/src/js/serial.js @@ -47,7 +47,8 @@ const serial = { self.connectionType = 'serial'; chrome.serial.connect(path, options, function (connectionInfo) { - if (connectionInfo && !self.openCanceled && !checkChromeRuntimeError()) { + self.failed = checkChromeRuntimeError(); + if (connectionInfo && !self.openCanceled && !self.failed) { self.connected = true; self.connectionId = connectionInfo.connectionId; self.bitrate = connectionInfo.bitrate; @@ -65,6 +66,7 @@ const serial = { if (!self.failed++) { chrome.serial.setPaused(self.connectionId, false, function () { self.getInfo(function (getInfo) { + checkChromeRuntimeError(); if (getInfo) { if (!getInfo.paused) { console.log(`${self.connectionType}: connection recovered from last onReceiveError`); @@ -74,8 +76,6 @@ const serial = { gui_log(i18n.getMessage('serialUnrecoverable')); self.errorHandler(getInfo.error, 'receive'); } - } else { - checkChromeRuntimeError(); } }); }); @@ -87,13 +87,14 @@ const serial = { self.error = info.error; setTimeout(function() { chrome.serial.setPaused(info.connectionId, false, function() { - self.getInfo(function (_info) { - if (_info) { - if (_info.paused) { + checkChromeRuntimeError(); + self.getInfo(function (getInfo) { + if (getInfo) { + if (getInfo.paused) { // assume unrecoverable, disconnect console.log(`${self.connectionType}: connection did not recover from ${self.error} condition, disconnecting`); gui_log(i18n.getMessage('serialUnrecoverable')); - self.errorHandler(_info.error, 'receive'); + self.errorHandler(getInfo.error, 'receive'); } else { console.log(`${self.connectionType}: connection recovered from ${self.error} condition`); diff --git a/src/js/utils/common.js b/src/js/utils/common.js index bc5306c07c..f3a4ec7961 100644 --- a/src/js/utils/common.js +++ b/src/js/utils/common.js @@ -1,6 +1,7 @@ import semver from "semver"; import { mixerList } from "../model"; import CONFIGURATOR from "../data_storage"; +import { gui_log } from "../gui_log"; export function millitime() { return new Date().getTime(); @@ -39,7 +40,7 @@ export function isInt(n) { export function checkChromeRuntimeError() { if (chrome.runtime.lastError) { console.error(`Chrome API Error: ${chrome.runtime.lastError.message}.\n Traced ${new Error().stack}`); - + gui_log(`Chrome API Error: ${chrome.runtime.lastError.message}.`); return true; } return false;