{"record":{"id":"2d219a0d9d82209b","repo":"VictoriaMetrics/VictoriaMetrics","slug":"cannot-unmarshal-type","errorCode":null,"errorMessage":"cannot unmarshal type","messagePattern":"cannot unmarshal type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/protoparser/datadogv2/parser.go","lineNumber":302,"sourceCode":"\nfunc (r *Resource) unmarshalProtobuf(src []byte) (err error) {\n\t// message Resource {\n\t//   string type = 1;\n\t//   string name = 2;\n\t// }\n\t//\n\t// See https://github.com/DataDog/agent-payload/blob/d7c5dcc63970d0e19678a342e7718448dd777062/proto/metrics/agent_payload.proto\n\tvar fc easyproto.FieldContext\n\tfor len(src) > 0 {\n\t\tsrc, err = fc.NextField(src)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"cannot unmarshal next field: %w\", err)\n\t\t}\n\t\tswitch fc.FieldNum {\n\t\tcase 1:\n\t\t\ttyp, ok := fc.String()\n\t\t\tif !ok {\n\t\t\t\treturn fmt.Errorf(\"cannot unmarshal type\")\n\t\t\t}\n\t\t\tr.Type = typ\n\t\tcase 2:\n\t\t\tname, ok := fc.String()\n\t\t\tif !ok {\n\t\t\t\treturn fmt.Errorf(\"cannot unmarshal name\")\n\t\t\t}\n\t\t\tr.Name = name\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":284,"sourceCodeEnd":315,"githubUrl":"https://github.com/VictoriaMetrics/VictoriaMetrics/blob/5079fb58f1e8e62113f90c945ad71586c797d770/lib/protoparser/datadogv2/parser.go#L284-L315","documentation":"Raised at lib/protoparser/datadogv2/parser.go:302 when Resource field 1 (string type) in a DataDog v2 series payload cannot be read: FieldContext.String() returned false because the field is not a valid length-delimited string. The resource, and the request containing it, is rejected.","triggerScenarios":"A Resource submessage encodes type (field 1) with a varint/fixed wire type instead of length-delimited, or its string length varint exceeds the remaining submessage bytes.","commonSituations":"Hand-rolled encoders writing resource type as a numeric enum; sender built from a divergent agent-payload proto; corrupted payloads truncated in transit.","solutions":["Confirm with protoc --decode_raw that field 1 of Resource is wire type 2 and decodes as UTF-8.","Fix the sender so `string type = 1;` is encoded as a length-delimited string via generated proto code.","Align the client's agent-payload proto version with the one VictoriaMetrics parses (commit d7c5dcc).","Log the wrapped inner error, reject the series with 400, and let the client retry with a correct payload."],"exampleFix":"// before: type encoded as numeric enum varint\npb.Resource{Type: pb.ResourceType_HOST} // typed enum, wrong wire type\n// after: encode as the string the schema defines\npb.Resource{Type: \"host\", Name: name}","handlingStrategy":"validation","validationCode":"// Resource.type must be a length-delimited string (field 1, wire type 2):\n// protoc --decode_raw < resource.bin  =>  \"1: \\\"host\\\"\"\nif r.GetType() == \"\" {\n\treturn errors.New(\"resource.type must be a non-empty string\")\n}","typeGuard":null,"tryCatchPattern":"if err := datadogv2.UnmarshalProtobuf(&req, body); err != nil {\n\tif strings.Contains(err.Error(), \"cannot unmarshal type\") {\n\t\tlog.Printf(\"resource type encoded with wrong wire type: %v\", err)\n\t}\n\thttp.Error(w, \"bad resource type field\", http.StatusBadRequest)\n\treturn\n}","preventionTips":["Encode resource type as `string type = 1;`, never as an enum or numeric varint.","Regenerate senders from the official agent-payload proto after any schema change.","Include payloads with resources in end-to-end ingestion tests.","Inspect failing payloads with protoc --decode_raw to confirm the wire type quickly."],"tags":["protobuf","datadog","wire-format","resources"],"backgroundTag":"protobuf-schema-mismatch","analyzedSha":"5079fb58f1e8e62113f90c945ad71586c797d770","analyzedAt":"2026-09-03T18:10:26.153Z","contentChangedAt":"2026-09-03T18:10:26.153Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}