From bf69a576bb4614aaece3f513d3f19251d2ec8a13 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 7 Oct 2022 15:57:18 +0100 Subject: [PATCH] Make unparseable message non-fatal There was code to handle unparseable messages from things like third party browser extensions but it caught a JSON parsing error, logged an error and then continued, which would throw an unhandled exception trying to read the `ack` property of `data` which had been left as `undefined`. Add a `return` to abort execution of the handler function and ignore the message instead. Also changes the error to warning, since it's not a fatal error. Add a comment to clarify the behaviour. From the existing comment, it looks like this was the original intention of the code, but the `return` was simply missed. --- www/common/outer/worker-channel.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/www/common/outer/worker-channel.js b/www/common/outer/worker-channel.js index a637d0cbe..528488f68 100644 --- a/www/common/outer/worker-channel.js +++ b/www/common/outer/worker-channel.js @@ -171,10 +171,12 @@ define([ var data; // apparently some browser extensions send messages to random targets // which can trigger parse errors that interrupt normal behaviour + // we therefore log a warning and ignore any messages we can't parse try { data = typeof(msg.data) === "object" ? msg.data : JSON.parse(msg.data); } catch (err) { - console.error(err); + console.warn(err); + return; } if (typeof(data.ack) !== "undefined") { if (acks[data.txid]) { acks[data.txid](!data.ack); }