diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-07-02 19:32:40 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-07-02 19:32:40 -0400 |
commit | e69d1615c4ff1cf93e51f83b66f7d32fe6baf942 (patch) | |
tree | 6cd214d59ccc49308a621c2444188e0130dd45bc /src | |
parent | f698352718d0f5461a41758ee99c2a85893e6390 (diff) | |
download | SMAPI-e69d1615c4ff1cf93e51f83b66f7d32fe6baf942.tar.gz SMAPI-e69d1615c4ff1cf93e51f83b66f7d32fe6baf942.tar.bz2 SMAPI-e69d1615c4ff1cf93e51f83b66f7d32fe6baf942.zip |
throw more useful error when JSON file is invalid (#314)
Diffstat (limited to 'src')
-rw-r--r-- | src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs | 16 |
1 files changed, 15 insertions, 1 deletions
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<TModel>(json, this.JsonSettings); + try + { + return JsonConvert.DeserializeObject<TModel>(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); + } } /// <summary>Save to a JSON file.</summary> |