From f7453a1600cbe2117216d2fd83b0bbd9774e76ee Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 14 Oct 2019 01:09:34 -0500 Subject: [PATCH] Add an error check for invalid JSON when importing a configuration. --- smx-config/Helpers.cs | 8 +++++++- smx-config/SMXJSON.cs | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/smx-config/Helpers.cs b/smx-config/Helpers.cs index 99b9900..3b56610 100644 --- a/smx-config/Helpers.cs +++ b/smx-config/Helpers.cs @@ -918,7 +918,13 @@ namespace smx_config // Import a saved JSON configuration to an SMXConfig. public static void ImportSettingsFromJSON(string json, ref SMX.SMXConfig config) { - Dictionary dict = SMXJSON.ParseJSON.Parse>(json); + Dictionary dict; + try { + dict = SMXJSON.ParseJSON.Parse>(json); + } catch(ParseError e) { + MessageBox.Show(e.Message, "Error importing configuration", MessageBoxButton.OK, MessageBoxImage.Warning); + return; + } // Read the thresholds. If any values are missing, we'll leave the value in config alone. if(config.fsr()) diff --git a/smx-config/SMXJSON.cs b/smx-config/SMXJSON.cs index f9cb2b2..d9880ea 100644 --- a/smx-config/SMXJSON.cs +++ b/smx-config/SMXJSON.cs @@ -9,7 +9,8 @@ namespace SMXJSON { public class JSONError: Exception { - public JSONError(string error) + public JSONError(string error): + base(error) { } };