tui-cs/Terminal.Gui · error · JsonException
Unexpected token type in TraceCategory array: {reader.TokenT
Error message
Unexpected token type in TraceCategory array: {reader.TokenType} What it means
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.
Source
Thrown at Terminal.Gui/Configuration/TraceCategoryJsonConverter.cs:47
throw new JsonException ($"Invalid TraceCategory value: '{value}'");
}
if (reader.TokenType == JsonTokenType.StartArray)
{
// Handle array format: ["Command", "Mouse"]
var result = TraceCategory.None;
while (reader.Read ())
{
if (reader.TokenType == JsonTokenType.EndArray)
{
break;
}
if (reader.TokenType != JsonTokenType.String)
{
throw new JsonException ($"Unexpected token type in TraceCategory array: {reader.TokenType}");
}
string value = reader.GetString ()!;
if (Enum.TryParse (value, true, out TraceCategory category))
{
result |= category;
}
else
{
throw new JsonException ($"Invalid TraceCategory value in array: '{value}'");
}
}
return result;
}
throw new JsonException ($"Unexpected token type for TraceCategory: {reader.TokenType}");
}View on GitHub (pinned to 2e47b11478)
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.
Example fix
// before "TraceCategory": ["Command", 2] // after "TraceCategory": ["Command", "Mouse"] // or scalar "TraceCategory": 6
Defensive patterns
Strategy: validation
Validate before calling
// Validate a TraceCategory array contains only strings
bool IsStringOnlyArray (JsonElement el)
=> el.ValueKind == JsonValueKind.Array && el.EnumerateArray ().All (e => e.ValueKind == JsonValueKind.String); Type guard
static bool IsTraceCategoryArrayValid (JsonElement el)
=> el.ValueKind == JsonValueKind.Array && el.EnumerateArray ().All (e => e.ValueKind == JsonValueKind.String && Enum.TryParse<TraceCategory> (e.GetString (), true, out _)); Try / catch
ConfigurationManager.ThrowOnJsonErrors = false;
Prevention
- Keep TraceCategory arrays homogeneous (all strings).
- Use the scalar integer form if you need numeric flag values.
- Validate with a JSON schema in CI.
When it happens
Trigger: Writing a TraceCategory array with mixed content such as ["Command", 2] or ["Mouse", true], or accidentally nesting [["Command"]].
Common situations: Mixing the integer and string forms inside one array; a JSON generator emitting numbers where strings were expected; copy-paste errors.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Invalid TraceCategory value: '{value}'
- Invalid TraceCategory value in array: '{value}'
- Unexpected token type for TraceCategory: {reader.TokenType}
- Unexpected StartObject token when parsing Attribute: {reader
- {propertyName}: Both Foreground and Background colors must b
AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13).
Data as JSON: /api/errors/1230def32ad82f85.
Report an issue: GitHub.