{"record":{"id":"f4d34274f4c4268f","repo":"XINCGer/Unity3DTraining","slug":"value-out-of-range","errorCode":null,"errorMessage":"Value out of range: ","messagePattern":"Value out of range: ","errorType":"validation","errorClass":"InvalidProtocolBufferException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs","lineNumber":644,"sourceCode":"                            return (ulong)value;\n                        case FieldType.Double:\n                            return value;\n                        case FieldType.Float:\n                            if (double.IsNaN(value))\n                            {\n                                return float.NaN;\n                            }\n                            if (value > float.MaxValue || value < float.MinValue)\n                            {\n                                if (double.IsPositiveInfinity(value))\n                                {\n                                    return float.PositiveInfinity;\n                                }\n                                if (double.IsNegativeInfinity(value))\n                                {\n                                    return float.NegativeInfinity;\n                                }\n                                throw new InvalidProtocolBufferException(\"Value out of range: \" + value);\n                            }\n                            return (float)value;\n                        case FieldType.Enum:\n                            CheckInteger(value);\n                            // Just return it as an int, and let the CLR convert it.\n                            // Note that we deliberately don't check that it's a known value.\n                            return (int)value;\n                        default:\n                            throw new InvalidProtocolBufferException(\"Unsupported conversion from JSON number for field type \" + field.FieldType);\n                    }\n                }\n                catch (OverflowException)\n                {\n                    throw new InvalidProtocolBufferException(\"Value out of range: \" + value);\n                }\n            }\n        }\n","sourceCodeStart":626,"sourceCodeEnd":662,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs#L626-L662","documentation":"When converting a JSON number to a float field, the parser checks that the double value fits in the float range; values whose magnitude exceeds float.MaxValue (other than infinities) throw this InvalidProtocolBufferException.","triggerScenarios":"Parsing JSON containing a numeric value like 1e60 for a float (google.protobuf.FloatValue or float field) — representable as double but out of float range.","commonSituations":"Sensor/scientific data serialized to JSON with values beyond ~3.4e38; unit mismatches (e.g. nanoseconds vs seconds producing huge numbers).","solutions":["Clamp or rescale the value at the producer before serializing.","Change the field type from float to double in the .proto if full range is needed.","Catch InvalidProtocolBufferException and substitute float.PositiveInfinity/NegativeInfinity if saturation is acceptable."],"exampleFix":"// before\n{\"temperature\": 1e60}  // float field\n// after\n{\"temperature\": 3.4e38} // or change field to double","handlingStrategy":"validation","validationCode":"// Check float-field values are within float range before parsing\nif (Math.Abs(rawValue) > (double)float.MaxValue && !double.IsInfinity(rawValue))\n    throw new ArgumentOutOfRangeException(nameof(rawValue), $\"{rawValue} exceeds float range\");","typeGuard":"static bool FitsInFloat(double d) => double.IsInfinity(d) || (d >= -3.40282347e38 && d <= 3.40282347e38);","tryCatchPattern":"try\n{\n    var msg = parser.Parse<T>(json);\n}\ncatch (InvalidProtocolBufferException ex) when (ex.Message.StartsWith(\"Value out of range:\") && ex.Message.Contains(\"float\"))\n{\n    // clamp and retry, or reject the record\n}","preventionTips":["Use double fields for data that can exceed ~3.4e38","Clamp/rescale values at the producer","Add schema-aware range validation on ingest"],"tags":["protobuf","json-parsing","float","range"],"backgroundTag":"value-out-of-range","analyzedSha":"016f98412ea5e11756b286736f479b66ab6216d5","analyzedAt":"2026-09-12T01:08:58.711Z","contentChangedAt":"2026-09-12T01:08:58.711Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}