{"record":{"id":"7a8219ece4b64496","repo":"CoplayDev/unity-mcp","slug":"failed-to-parse-float-at-index-i-arr-i","errorCode":null,"errorMessage":"Failed to parse float at index {i}: '{arr[i]}'","messagePattern":"Failed to parse float at index (.+?): '(.+?)'","errorType":"validation","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"MCPForUnity/Editor/Tools/ManageScene.cs","lineNumber":84,"sourceCode":"            public bool? autoRepair { get; set; }        // for validate with auto-repair\n        }\n\n        private static float[] ParseFloatArray(JToken token)\n        {\n            if (token == null || token.Type == JTokenType.Null) return null;\n            if (token.Type == JTokenType.Array)\n            {\n                var arr = (JArray)token;\n                var result = new float[arr.Count];\n                for (int i = 0; i < arr.Count; i++)\n                {\n                    try\n                    {\n                        result[i] = arr[i].ToObject<float>();\n                    }\n                    catch (Exception ex)\n                    {\n                        throw new Newtonsoft.Json.JsonException(\n                            $\"Failed to parse float at index {i}: '{arr[i]}'\", ex);\n                    }\n                }\n                return result;\n            }\n            // Single value → array of one\n            var single = ParamCoercion.CoerceFloatNullable(token);\n            return single.HasValue ? new[] { single.Value } : null;\n        }\n\n        private static SceneCommand ToSceneCommand(JObject p)\n        {\n            if (p == null) return new SceneCommand();\n            var toolParams = new ToolParams(p);\n            return new SceneCommand\n            {\n                action = (p[\"action\"]?.ToString() ?? string.Empty).Trim().ToLowerInvariant(),\n                name = p[\"name\"]?.ToString() ?? string.Empty,","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/MCPForUnity/Editor/Tools/ManageScene.cs#L66-L102","documentation":"ParseFloatArray iterates a JArray and calls ToObject<float> on each element. When an element cannot be converted to float, the exception is rethrown with the failing index and the raw token value for diagnosis.","triggerScenarios":"A float-array parameter (e.g. orbit_elevations, position/rotation arrays) contains a non-numeric value: a string like 'high', null, a boolean, or a nested object/array.","commonSituations":"An LLM sends strings instead of numbers; a payload mixes types; a caller reuses a value meant for another field.","solutions":["Ensure every element of the array is a numeric value.","Validate the array contents before sending the command.","If sending a single value, pass it directly (the function coerces a single value to a one-element array)."],"exampleFix":"// before\n{ \"orbit_elevations\": [\"low\", 30, 60] }\n// after\n{ \"orbit_elevations\": [10, 30, 60] }","handlingStrategy":"type-guard","validationCode":"if (token.Type == JTokenType.Array)\n{\n    for (int i = 0; i < token.Count(); i++)\n        if (token[i].Type != JTokenType.Float && token[i].Type != JTokenType.Integer)\n            throw new ArgumentException($\"Array element {i} is not numeric: '{token[i]}'\");\n}","typeGuard":"static bool IsNumericArray(JToken t)\n{\n    if (t == null || t.Type == JTokenType.Null) return true;\n    if (t.Type == JTokenType.Float || t.Type == JTokenType.Integer) return true;\n    if (t.Type != JTokenType.Array) return false;\n    foreach (var e in t)\n        if (e.Type != JTokenType.Float && e.Type != JTokenType.Integer) return false;\n    return true;\n}","tryCatchPattern":null,"preventionTips":["Send only numeric values in float-array parameters.","Validate array element types before dispatching scene commands.","Prefer numbers over numeric strings in payloads."],"tags":["json","validation","scene"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}