{"record":{"id":"1230def32ad82f85","repo":"tui-cs/Terminal.Gui","slug":"unexpected-token-type-in-tracecategory-array-rea","errorCode":null,"errorMessage":"Unexpected token type in TraceCategory array: {reader.TokenType}","messagePattern":"Unexpected token type in TraceCategory array: (.+?)","errorType":"validation","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Configuration/TraceCategoryJsonConverter.cs","lineNumber":47,"sourceCode":"\n            throw new JsonException ($\"Invalid TraceCategory value: '{value}'\");\n        }\n\n        if (reader.TokenType == JsonTokenType.StartArray)\n        {\n            // Handle array format: [\"Command\", \"Mouse\"]\n            var result = TraceCategory.None;\n\n            while (reader.Read ())\n            {\n                if (reader.TokenType == JsonTokenType.EndArray)\n                {\n                    break;\n                }\n\n                if (reader.TokenType != JsonTokenType.String)\n                {\n                    throw new JsonException ($\"Unexpected token type in TraceCategory array: {reader.TokenType}\");\n                }\n                string value = reader.GetString ()!;\n\n                if (Enum.TryParse (value, true, out TraceCategory category))\n                {\n                    result |= category;\n                }\n                else\n                {\n                    throw new JsonException ($\"Invalid TraceCategory value in array: '{value}'\");\n                }\n            }\n\n            return result;\n        }\n\n        throw new JsonException ($\"Unexpected token type for TraceCategory: {reader.TokenType}\");\n    }","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Configuration/TraceCategoryJsonConverter.cs#L29-L65","documentation":"Thrown by TraceCategoryJsonConverter.Read while parsing the array form of a TraceCategory value: an element inside the JSON array is not a string token. The array form ([\"Command\",\"Mouse\"]) requires every element to be a JsonTokenType.String; numbers, booleans, null, or nested arrays/objects are rejected per-element.","triggerScenarios":"Writing a TraceCategory array with mixed content such as [\"Command\", 2] or [\"Mouse\", true], or accidentally nesting [[\"Command\"]].","commonSituations":"Mixing the integer and string forms inside one array; a JSON generator emitting numbers where strings were expected; copy-paste errors.","solutions":["Make every element of the TraceCategory array a string literal that names a TraceCategory member.","If you want a numeric, switch the whole value to the scalar integer form (e.g. 6) instead of an array.","Validate the array with a JSON schema or jq to confirm all elements are strings."],"exampleFix":"// before\n\"TraceCategory\": [\"Command\", 2]\n// after\n\"TraceCategory\": [\"Command\", \"Mouse\"]\n// or scalar\n\"TraceCategory\": 6","handlingStrategy":"validation","validationCode":"// Validate a TraceCategory array contains only strings\nbool IsStringOnlyArray (JsonElement el)\n    => el.ValueKind == JsonValueKind.Array && el.EnumerateArray ().All (e => e.ValueKind == JsonValueKind.String);","typeGuard":"static bool IsTraceCategoryArrayValid (JsonElement el)\n    => el.ValueKind == JsonValueKind.Array && el.EnumerateArray ().All (e => e.ValueKind == JsonValueKind.String && Enum.TryParse<TraceCategory> (e.GetString (), true, out _));","tryCatchPattern":"ConfigurationManager.ThrowOnJsonErrors = false;","preventionTips":["Keep TraceCategory arrays homogeneous (all strings).","Use the scalar integer form if you need numeric flag values.","Validate with a JSON schema in CI."],"tags":["config","json","tracing","tracecategory","enum"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}