{"record":{"id":"7a7c995041ce471b","repo":"mgth/LittleBigMouse","slug":"unexpected-token-reader-tokentype-for-a-border-resistance","errorCode":null,"errorMessage":"Unexpected token {reader.TokenType} for a border resistance side.","messagePattern":"Unexpected token (.+?) for a border resistance side\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"LittleBigMouse.Plugins/LittleBigMouse.Plugins.Core/Persistence/BorderSideDtoJsonConverter.cs","lineNumber":43,"sourceCode":"    public override BorderSideDto? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)\n    {\n        switch (reader.TokenType)\n        {\n            case JsonTokenType.Null:\n                return null;\n\n            // Legacy: a single resistance governing every crossing.\n            case JsonTokenType.Number:\n            {\n                var value = reader.GetDouble();\n                return new BorderSideDto { Move = value, Drag = value };\n            }\n\n            case JsonTokenType.StartObject:\n                break;\n\n            default:\n                throw new JsonException($\"Unexpected token {reader.TokenType} for a border resistance side.\");\n        }\n\n        var dto = new BorderSideDto();\n\n        while (reader.Read())\n        {\n            if (reader.TokenType == JsonTokenType.EndObject) return dto;\n            if (reader.TokenType != JsonTokenType.PropertyName) continue;\n\n            var name = reader.GetString();\n            reader.Read();\n\n            switch (name)\n            {\n                case nameof(BorderSideDto.Move):\n                    dto.Move = ReadNullableDouble(ref reader);\n                    break;\n                case nameof(BorderSideDto.MoveBlock):","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/mgth/LittleBigMouse/blob/7a42f01d47d99d223b8ee33ba4019af82adf1c48/LittleBigMouse.Plugins/LittleBigMouse.Plugins.Core/Persistence/BorderSideDtoJsonConverter.cs#L25-L61","documentation":"BorderSideDtoJsonConverter.Read deserializes a border resistance side from JSON. It accepts a string, number, or start of an object as the value token; any other JSON token (true, false, null, start of array, etc.) makes it throw this JsonException. The library throws it to fail fast on malformed settings JSON rather than silently producing a default BorderSideDto.","triggerScenarios":"Calling JsonSerializer.Deserialize on JSON where a border-resistance-side property is set to a literal like true, false, null, or an array (e.g. \"left\": [1,2] or \"left\": null) instead of a string, number, or object.","commonSituations":"Hand-edited LittleBigMouse settings files, config generated by a different/older schema version, or a serialization bug writing null for an unconfigured side.","solutions":["Open the settings JSON and replace the offending value for the border side with a valid string, number, or object form.","If the value is intentionally unset, use the type's default representation (e.g. a number or empty object) rather than null.","Regenerate the settings file from the app UI so it matches the current schema instead of patching by hand.","Catch JsonException around Deserialize and fall back to default border settings."],"exampleFix":"// before\n\"borderResistance\": { \"left\": null }\n// after\n\"borderResistance\": { \"left\": 0 }","handlingStrategy":"validation","validationCode":"// before deserializing, sanity-check the raw JSON value type for border sides\nusing var doc = System.Text.Json.JsonDocument.Parse(json);\nvar side = doc.RootElement.GetProperty(\"left\");\nif (side.ValueKind is not (JsonValueKind.String or JsonValueKind.Number or JsonValueKind.Object))\n    throw new FormatException($\"Border side token {side.ValueKind} is not a valid resistance value.\");","typeGuard":"static bool IsValidBorderSideToken(JsonTokenType t) =>\n    t is JsonTokenType.String or JsonTokenType.Number or JsonTokenType.StartObject;","tryCatchPattern":"try\n{\n    var dto = JsonSerializer.Deserialize<BorderSideDto>(json, options);\n}\ncatch (JsonException ex)\n{\n    Log.LogWarning(ex, \"Invalid border resistance side JSON; using defaults.\");\n    dto = new BorderSideDto();\n}","preventionTips":["Never write null/true/false/arrays into border-side settings fields.","Always serialize BorderSideDto through the same converter used for deserialization.","Validate settings JSON with a schema check on load before handing it to the converter."],"tags":["json","deserialization","settings","custom-converter"],"backgroundTag":"json-parse-error","analyzedSha":"7a42f01d47d99d223b8ee33ba4019af82adf1c48","analyzedAt":"2026-09-16T00:35:00.514Z","contentChangedAt":"2026-09-16T00:35:00.514Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}