{"record":{"id":"f98204d82344a83b","repo":"XINCGer/Unity3DTraining","slug":"value-not-an-integer","errorCode":null,"errorMessage":"Value not an integer: ","messagePattern":"Value not an integer: ","errorType":"validation","errorClass":"InvalidProtocolBufferException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs","lineNumber":667,"sourceCode":"        private static void CheckInteger(double value)\n        {\n            if (double.IsInfinity(value) || double.IsNaN(value))\n            {\n                throw new InvalidProtocolBufferException(\"Value not an integer: \" + value);\n            }\n            if (value != Math.Floor(value))\n            {\n                throw new InvalidProtocolBufferException(\"Value not an integer: \" + value);\n            }\n        }","sourceCodeStart":649,"sourceCodeEnd":685,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs#L649-L685","documentation":"CheckInteger is a validation helper used when parsing a JSON number into an enum field. It rejects any double that is infinity, NaN, or has a fractional part, since enums in proto3 JSON must be plain integers. The faulting input is the numeric JSON token being converted, echoed in the message.","triggerScenarios":"Parsing a JSON document where an enum field is given a JSON number that is not a whole number (e.g. 1.5) or a special value like Infinity/NaN.","commonSituations":"Malformed or hand-written JSON payload sent to a protobuf parser; a client serializing an enum with a computed float value; servers receiving rounding artifacts or NaN from upstream data.","solutions":["Correct the JSON payload so enum fields carry integer values.","Wrap JsonParser.Parse in try/catch for InvalidProtocolBufferException and return a descriptive 400-style error to the sender.","Validate numeric fields (finite, integral) before serialization on the producing side."],"exampleFix":"Fix the JSON so the enum is a whole number, e.g. \"status\": 2 instead of \"status\": 2.5; on the client, cast the enum value to int before emitting JSON.","handlingStrategy":"validation","validationCode":"// Reject non-finite or fractional values before serializing integer fields\nstatic void EnsureInteger(object value)\n{\n    double d = Convert.ToDouble(value);\n    if (double.IsNaN(d) || double.IsInfinity(d) || d != Math.Floor(d))\n        throw new FormatException($\"Value {d} is not an integer\");\n}","typeGuard":"static bool IsWholeNumber(double v) => !double.IsNaN(v) && !double.IsInfinity(v) && v == Math.Floor(v);","tryCatchPattern":"try\n{\n    var msg = parser.Parse<T>(json);\n}\ncatch (InvalidProtocolBufferException ex) when (ex.Message.StartsWith(\"Value not an integer:\"))\n{\n    // round and retry, or surface a data-quality error\n}","preventionTips":["Emit enums as integer literals in proto3 JSON, never floats or computed doubles.","Add schema/JSON validation at API boundaries to catch non-integral enum values early."],"tags":["protobuf","json-parsing","integer","nan"],"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-16T09:17:16.951Z"}