From 8fa96c2836d0fee0a6d68e990587a1e2d0ba3cd3 Mon Sep 17 00:00:00 2001 From: Sam Detweiler Date: Sun, 4 Oct 2020 12:13:08 -0500 Subject: [PATCH 1/3] add error handler to json parsing of translation files --- js/translator.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/js/translator.js b/js/translator.js index 0f4bc00a..43b65297 100644 --- a/js/translator.js +++ b/js/translator.js @@ -19,7 +19,15 @@ var Translator = (function () { xhr.open("GET", file, true); xhr.onreadystatechange = function () { if (xhr.readyState === 4 && xhr.status === 200) { - callback(JSON.parse(xhr.responseText)); + // needs error handler try/catch at least + let fileinfo = null; + try { + fileinfo = JSON.parse(xhr.responseText); + } catch (exception) { + // nothing here, but don't die + console.log(" loading json file failed =" + file); + } + callback(fileinfo); } }; xhr.send(null); From 69efca0bdbfb0e088ca122098e2449d484abbfd6 Mon Sep 17 00:00:00 2001 From: Sam Detweiler Date: Mon, 5 Oct 2020 10:45:07 -0500 Subject: [PATCH 2/3] use Log.error instead of console.log for error message, shows in output --- js/translator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/translator.js b/js/translator.js index 43b65297..5dc50045 100644 --- a/js/translator.js +++ b/js/translator.js @@ -25,7 +25,7 @@ var Translator = (function () { fileinfo = JSON.parse(xhr.responseText); } catch (exception) { // nothing here, but don't die - console.log(" loading json file failed =" + file); + Log.error(" loading json file =" + file + " failed"); } callback(fileinfo); } From 6440d2289c22b4a02d740d1801ab9fba566c5696 Mon Sep 17 00:00:00 2001 From: Sam Detweiler Date: Mon, 5 Oct 2020 12:58:10 -0500 Subject: [PATCH 3/3] fix translation files with comments crashing UI --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4cae705..246effd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](https://semver.org/). ❤️ **Donate:** Enjoying MagicMirror²? [Please consider a donation!](https://magicmirror.builders/donate) With your help we can continue to improve the MagicMirror² +### Fixed + +- JSON Parse translation files with comments crashing UI + ## [2.13.0] - 2020-10-01 Special thanks to the following contributors: @bryanzzhu, @bugsounet, @chamakura, @cjbrunner, @easyas314, @larryare, @oemel09, @rejas, @sdetweil & @sthuber90.