Fixes #2629 - Config Manager error logging improvements (#2630)

* Fixes #2629

* Fixed broken unit tests (which were already broken but latent)

* Removed test code
This commit is contained in:
Tig
2023-05-13 01:23:37 +02:00
committed by GitHub
parent 4bde80cfb7
commit f3ab1fb1bd
5 changed files with 623 additions and 627 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -7,6 +7,10 @@ namespace Terminal.Gui {
class DictionaryJsonConverter<T> : JsonConverter<Dictionary<string, T>> {
public override Dictionary<string, T> Read (ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.StartArray) {
throw new JsonException ($"Expected a JSON array (\"[ {{ ... }} ]\"), but got \"{reader.TokenType}\".");
}
var dictionary = new Dictionary<string, T> ();
while (reader.Read ()) {
if (reader.TokenType == JsonTokenType.StartObject) {

View File

@@ -100,7 +100,7 @@ namespace Terminal.Gui {
public override scopeT Read (ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.StartObject) {
throw new JsonException ($"Expected a JSON object, but got \"{reader.TokenType}\".");
throw new JsonException ($"Expected a JSON object (\"{{ \"propName\" : ... }}\"), but got \"{reader.TokenType}\".");
}
var scope = (scopeT)Activator.CreateInstance (typeof (scopeT))!;

View File

@@ -11,6 +11,11 @@
// null).
//
"$schema": "https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json",
// Set this to true in a .config file to be loaded to cause JSON parsing errors
// to throw exceptions.
"ConfigurationManager.ThrowOnJsonErrors": false,
"Application.AlternateBackwardKey": {
"Key": "PageUp",
"Modifiers": [

View File

@@ -544,8 +544,7 @@ namespace Terminal.Gui.ConfigurationTests {
// "yellow" is not a color
string json = @"
{
""Themes"" : {
""ThemeDefinitions"" : [
""Themes"" : [
{
""Default"" : {
""ColorSchemes"": [
@@ -560,8 +559,7 @@ namespace Terminal.Gui.ConfigurationTests {
]
}
}
]
}
]
}";
JsonException jsonException = Assert.Throws<JsonException> (() => ConfigurationManager.Settings.Update (json, "test"));
@@ -570,8 +568,7 @@ namespace Terminal.Gui.ConfigurationTests {
// AbNormal is not a ColorScheme attribute
json = @"
{
""Themes"" : {
""ThemeDefinitions"" : [
""Themes"" : [
{
""Default"" : {
""ColorSchemes"": [
@@ -586,8 +583,7 @@ namespace Terminal.Gui.ConfigurationTests {
]
}
}
]
}
]
}";
jsonException = Assert.Throws<JsonException> (() => ConfigurationManager.Settings.Update (json, "test"));
@@ -596,8 +592,7 @@ namespace Terminal.Gui.ConfigurationTests {
// Modify hotNormal background only
json = @"
{
""Themes"" : {
""ThemeDefinitions"" : [
""Themes"" : [
{
""Default"" : {
""ColorSchemes"": [
@@ -611,8 +606,7 @@ namespace Terminal.Gui.ConfigurationTests {
]
}
}
]
}
]
}";
jsonException = Assert.Throws<JsonException> (() => ConfigurationManager.Settings.Update (json, "test"));
@@ -641,8 +635,7 @@ namespace Terminal.Gui.ConfigurationTests {
// "yellow" is not a color
string json = @"
{
""Themes"" : {
""ThemeDefinitions"" : [
""Themes"" : [
{
""Default"" : {
""ColorSchemes"": [
@@ -657,7 +650,6 @@ namespace Terminal.Gui.ConfigurationTests {
]
}
}
]
}
}";
@@ -666,8 +658,7 @@ namespace Terminal.Gui.ConfigurationTests {
// AbNormal is not a ColorScheme attribute
json = @"
{
""Themes"" : {
""ThemeDefinitions"" : [
""Themes"" : [
{
""Default"" : {
""ColorSchemes"": [
@@ -682,7 +673,6 @@ namespace Terminal.Gui.ConfigurationTests {
]
}
}
]
}
}";
@@ -691,8 +681,7 @@ namespace Terminal.Gui.ConfigurationTests {
// Modify hotNormal background only
json = @"
{
""Themes"" : {
""ThemeDefinitions"" : [
""Themes"" : [
{
""Default"" : {
""ColorSchemes"": [
@@ -706,7 +695,6 @@ namespace Terminal.Gui.ConfigurationTests {
]
}
}
]
}
}";