{"record":{"id":"a85299bb2e9a32dc","repo":"tui-cs/Terminal.Gui","slug":"unexpected-end-of-json-while-reading-mouseflags-ar","errorCode":null,"errorMessage":"Unexpected end of JSON while reading MouseFlags array.","messagePattern":"Unexpected end of JSON while reading MouseFlags array\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Configuration/MouseFlagsArrayJsonConverter.cs","lineNumber":45,"sourceCode":"        while (reader.Read ())\n        {\n            if (reader.TokenType == JsonTokenType.EndArray)\n            {\n                return mouseFlagsList.ToArray ();\n            }\n\n            if (reader.TokenType != JsonTokenType.String)\n            {\n                throw new JsonException ($\"Expected string token in MouseFlags array, got {reader.TokenType}.\");\n            }\n\n            string mouseFlagsString = reader.GetString ()!;\n            mouseFlagsString = mouseFlagsString.Replace (\"+\", \", \").Replace (\"|\", \", \");\n\n            mouseFlagsList.Add (Enum.TryParse (mouseFlagsString, true, out MouseFlags mouseFlags) ? mouseFlags : MouseFlags.None);\n        }\n\n        throw new JsonException (\"Unexpected end of JSON while reading MouseFlags array.\");\n    }\n\n    /// <inheritdoc/>\n    public override void Write (Utf8JsonWriter writer, MouseFlags []? value, JsonSerializerOptions options)\n    {\n        if (value is null)\n        {\n            writer.WriteNullValue ();\n\n            return;\n        }\n\n        writer.WriteStartArray ();\n\n        foreach (MouseFlags mouseFlags in value)\n        {\n            writer.WriteStringValue (mouseFlags.ToString ().Replace (\", \", \"+\"));\n        }","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Configuration/MouseFlagsArrayJsonConverter.cs#L27-L63","documentation":"Thrown by MouseFlagsArrayJsonConverter.Read (MouseFlagsArrayJsonConverter.cs:45) when reader.Read() returns false (end of stream) before an EndArray token is encountered. The JSON is truncated or missing the closing bracket of a MouseFlags[] array.","triggerScenarios":"The config JSON stream ends mid-array: missing ']' after the last mouse-flag string, or the file/stream was cut off. reader.Read() returns false inside the while loop, exiting without hitting EndArray.","commonSituations":"Truncated config file (incomplete write, dropped closing bracket). Streaming deserialization over a truncated buffer. Templating that dropped trailing content.","solutions":["Add the missing closing ']' for the MouseFlags[] array.","Validate the JSON parses with System.Text.Json.JsonDocument.Parse before handing it to ConfigurationManager to surface truncation with a clearer message.","Write config files atomically (temp file + rename) to avoid partial writes.","Buffer the complete document before deserialization when streaming."],"exampleFix":"// before (truncated)\n\"Click\": [\"Button1Clicked\", \"WheeledUp\"\n\n// after\n\"Click\": [\"Button1Clicked\", \"WheeledUp\"]","handlingStrategy":"validation","validationCode":"using System.Text.Json;\n\nstatic bool JsonIsCompleteAndValid (string json)\n{\n    try\n    {\n        using JsonDocument doc = JsonDocument.Parse (json);\n        return true;\n    }\n    catch (JsonException) { return false; }\n}\n\nif (!JsonIsCompleteAndValid (configJson))\n{\n    // The JSON is truncated/malformed; do not hand it to ConfigurationManager.\n}","typeGuard":"static bool IsCompleteJson (string json)\n{\n    try { using JsonDocument.Parse (json); return true; } catch { return false; }\n}","tryCatchPattern":"try\n{\n    ConfigurationManager.Load (configJson);\n}\ncatch (JsonException ex) when (ex.Message.Contains (\"Unexpected end of JSON while reading MouseFlags array\"))\n{\n    // The MouseFlags[] array is missing its closing ']'. Repair the JSON and reload.\n}","preventionTips":["Always close MouseFlags[] arrays with ']'.","Pre-validate config JSON with JsonDocument.Parse before loading.","Write config files atomically (temp + rename) to avoid partial writes.","Buffer streamed JSON completely before deserialization."],"tags":["json","configuration","mouse","mousebindings","malformed-json","serialization"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}