From e69d1615c4ff1cf93e51f83b66f7d32fe6baf942 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 2 Jul 2017 19:32:40 -0400 Subject: throw more useful error when JSON file is invalid (#314) --- .../Framework/Serialisation/JsonHelper.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs') diff --git a/src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs b/src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs index 64d8738e..6431394c 100644 --- a/src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs +++ b/src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs @@ -51,7 +51,21 @@ namespace StardewModdingAPI.Framework.Serialisation } // deserialise model - return JsonConvert.DeserializeObject(json, this.JsonSettings); + try + { + return JsonConvert.DeserializeObject(json, this.JsonSettings); + } + catch (JsonReaderException ex) + { + string message = $"The file at {fullPath} doesn't seem to be valid JSON."; + + string text = File.ReadAllText(fullPath); + if (text.Contains("“") || text.Contains("”")) + message += " Found curly quotes in the text; note that only straight quotes are allowed in JSON."; + + message += $"\nTechnical details: {ex.Message}"; + throw new JsonReaderException(message); + } } /// Save to a JSON file. -- cgit From e2b9a4bab3e078851a289ad0a19b555dde09308e Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 6 Jul 2017 15:17:47 -0400 Subject: serialise SButtons as string in config.json (#316) --- src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs') diff --git a/src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs b/src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs index 6431394c..3193aa3c 100644 --- a/src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs +++ b/src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using Microsoft.Xna.Framework.Input; using Newtonsoft.Json; +using StardewModdingAPI.Utilities; namespace StardewModdingAPI.Framework.Serialisation { @@ -19,7 +20,7 @@ namespace StardewModdingAPI.Framework.Serialisation ObjectCreationHandling = ObjectCreationHandling.Replace, // avoid issue where default ICollection values are duplicated each time the config is loaded Converters = new List { - new SelectiveStringEnumConverter(typeof(Buttons), typeof(Keys)) + new SelectiveStringEnumConverter(typeof(Buttons), typeof(Keys), typeof(SButton)) } }; -- cgit