From c34f1e93dd21dc02842d02e91633f4a57b3f8d66 Mon Sep 17 00:00:00 2001 From: Joey Beauvais-Feisthauer Date: Sun, 26 Nov 2023 18:03:05 -0500 Subject: [PATCH] Add alert if JSON is invalid --- web_ext/sseq_gui/interface/index.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/web_ext/sseq_gui/interface/index.js b/web_ext/sseq_gui/interface/index.js index 4b1cfb96c..7e7d81d03 100644 --- a/web_ext/sseq_gui/interface/index.js +++ b/web_ext/sseq_gui/interface/index.js @@ -278,11 +278,19 @@ messageHandler.Error = m => { document.getElementById('json-upload').addEventListener('change', () => { const file = document.getElementById('json-upload').files[0]; const fileReader = new FileReader(); + fileReader.onload = e => { - // Remove whitespace to shorten URL - const json = JSON.stringify(JSON.parse(e.target.result)); - window.location = `?module_json=${encodeURIComponent(json)}`; + try { + // Attempt to parse JSON + const json = JSON.stringify(JSON.parse(e.target.result)); + window.location = `?module_json=${encodeURIComponent(json)}`; + } catch (error) { + // If an error occurs, display an error message + alert('Invalid JSON file. Please upload a valid JSON file.'); + console.error('Error parsing JSON:', error); + } }; + fileReader.readAsText(file, 'UTF-8'); });