{"record":{"id":"f49e4848bd520c81","repo":"XINCGer/Unity3DTraining","slug":"unexpected-token-type-f49e48","errorCode":null,"errorMessage":"Unexpected token type: ","messagePattern":"Unexpected token type: ","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs","lineNumber":465,"sourceCode":"                    {\n                        var field = fields[Value.StructValueFieldNumber];\n                        var structMessage = NewMessageForField(field);\n                        tokenizer.PushBack(firstToken);\n                        Merge(structMessage, tokenizer);\n                        field.Accessor.SetValue(message, structMessage);\n                        return;\n                    }\n                case JsonToken.TokenType.StartArray:\n                    {\n                        var field = fields[Value.ListValueFieldNumber];\n                        var list = NewMessageForField(field);\n                        tokenizer.PushBack(firstToken);\n                        Merge(list, tokenizer);\n                        field.Accessor.SetValue(message, list);\n                        return;\n                    }\n                default:\n                    throw new InvalidOperationException(\"Unexpected token type: \" + firstToken.Type);\n            }\n        }\n\n        private void MergeStruct(IMessage message, JsonTokenizer tokenizer)\n        {\n            var token = tokenizer.Next();\n            if (token.Type != JsonToken.TokenType.StartObject)\n            {\n                throw new InvalidProtocolBufferException(\"Expected object value for Struct\");\n            }\n            tokenizer.PushBack(token);\n\n            var field = message.Descriptor.Fields[Struct.FieldsFieldNumber];\n            MergeMapField(message, field, tokenizer);\n        }\n\n        private void MergeAny(IMessage message, JsonTokenizer tokenizer)\n        {","sourceCodeStart":447,"sourceCodeEnd":483,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs#L447-L483","documentation":"MergeStructValue dispatches on the first JSON token to parse a google.protobuf.Value (Value message): objects, arrays, strings, numbers, and booleans are all handled; any other first-token type falls through to this InvalidOperationException. It represents an internal dispatch gap in the Value parser.","triggerScenarios":"Parsing a google.protobuf.Value/Struct payload whose first token is none of StartObject/StartArray/StringValue/Number/true/false — typically a Null token (null JSON value) or a tokenizer-emitted Name token reaching MergeStructValue directly.","commonSituations":"JSON with a literal null assigned to a Value-typed field reaching this dispatch (null handling is unimplemented elsewhere too); custom tokenizers producing unexpected token types; internal bug reports from deep nested Struct payloads.","solutions":["Avoid null as the JSON value for google.protobuf.Value fields; use the Value null_value variant represented per canonical mapping (this dispatch path usually catches a routing gap).","Upgrade Google.Protobuf to a version where MergeStructValue's switch covers all canonical Value cases.","Validate the JSON tree for Value/Struct fields: only objects, arrays, strings, numbers, and booleans are supported dispatch targets.","Catch InvalidOperationException and log the firstToken.Type from the message to identify the unsupported token."],"exampleFix":"// before\n{\"payload\": null}  // payload is google.protobuf.Value\n\n// after: use the null variant explicitly if the version requires it\n{\"payload\": {\"nullValue\": \"NULL_VALUE\"}}","handlingStrategy":"validation","validationCode":"// google.protobuf.Value accepts object|array|string|number|boolean only\nfunction isValidValuePayload(v) {\n  return v === 'string' || ['object','array','string','number','boolean'].includes(v) === false ? false : true;\n}\n// practical check: reject null before it reaches Value dispatch\nif (payload.payloadField === null) throw new Error('null not supported for Value dispatch in this parser version');","typeGuard":"function isSupportedValueToken(v) { return v !== null && v !== undefined; }","tryCatchPattern":"try { var msg = JsonParser.Default.Parse<T>(json); }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Unexpected token type\")) { /* log token type; fall back to preprocessed parse */ }","preventionTips":["Keep Google.Protobuf up to date so Value parsing covers all canonical cases","Avoid null JSON values for Value/Struct fields; use the null_value variant mapping","Fuzz-test Struct/Value payloads against the parser in CI"],"tags":["protobuf","json-parsing","struct","value-type","invalid-operation"],"backgroundTag":"unsupported-operation","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"}