diff options
-rw-r--r-- | release-notes.md | 1 | ||||
-rw-r--r-- | src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs | 16 |
2 files changed, 16 insertions, 1 deletions
diff --git a/release-notes.md b/release-notes.md index 4b4a3447..ae2f853d 100644 --- a/release-notes.md +++ b/release-notes.md @@ -21,6 +21,7 @@ For players: * `list_items` now shows all items in the game. You can search by item type like `list_items weapon`, or search by item name like `list_items galaxy sword`. * `list_items` now also matches translated item names when playing in another language. * `list_item_types` is a new command to see a list of item types. +* Added clearer error when a `config.json` is invalid. For modders: * You can now specify minimum dependency versions in `manifest.json`. 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> |