{"record":{"id":"36f4df71ff65f2c2","repo":"apache/beam","slug":"bytesvalue-unmarshal-failed","errorCode":null,"errorMessage":"BytesValue unmarshal failed","messagePattern":"BytesValue unmarshal failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/protox/any.go","lineNumber":82,"sourceCode":"\n// PackBase64Proto encodes a proto message into a base64-encoded BytesValue message.\nfunc PackBase64Proto(in proto.Message) (*protobuf.Any, error) {\n\tdata, err := EncodeBase64(in)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn PackBytes([]byte(data))\n}\n\n// UnpackBytes removes the BytesValue wrapper.\nfunc UnpackBytes(data *protobuf.Any) ([]byte, error) {\n\tif data.TypeUrl != bytesValueTypeURL {\n\t\treturn nil, errors.Errorf(\"bad type: %v, want %v\", data.TypeUrl, bytesValueTypeURL)\n\t}\n\n\tvar buf protobufw.BytesValue\n\tif err := proto.Unmarshal(data.Value, &buf); err != nil {\n\t\treturn nil, errors.Wrap(err, \"BytesValue unmarshal failed\")\n\t}\n\treturn buf.Value, nil\n}\n\n// PackBytes applies a BytesValue wrapper to the supplied bytes.\nfunc PackBytes(in []byte) (*protobuf.Any, error) {\n\tvar buf protobufw.BytesValue\n\tbuf.Value = in\n\tb, err := proto.Marshal(&buf)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar out protobuf.Any\n\tout.TypeUrl = bytesValueTypeURL\n\tout.Value = b\n\treturn &out, nil\n}","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/protox/any.go#L64-L100","documentation":"Wrap returned by UnpackBytes when proto.Unmarshal of the Any's value into a wrappers.BytesValue fails. The TypeUrl check has already passed, so the payload bytes exist but are not a validly encoded BytesValue proto — corrupt or version-incompatible packed data. Callers such as UnpackProto and UnpackBase64Proto surface this directly.","triggerScenarios":"proto.Unmarshal in UnpackBytes returns an error because data.Value is corrupted, truncated, empty, or was serialized by an incompatible proto version.","commonSituations":"Hand-crafted or corrupted Any payloads, binary data mangled by a transport that is not 8-bit clean, or mixing proto2/proto3 wire formats across pipeline stages.","solutions":["Verify the payload bytes are a complete, unmodified protobuf serialization of BytesValue","Re-pack the data with PackBytes on the producer side instead of manually assembling the Any","Log/inspect data.Value length and bytes to detect truncation or corruption in transit"],"exampleFix":"// before\npacked, _ := ptypes.MarshalAny(&wrapperspb.BytesValue{Value: data}) // manual assembly risk\n// after\npacked, err := protox.PackBytes(data)\nif err != nil { return err }","handlingStrategy":"try-catch","validationCode":"if len(data.GetValue()) == 0 { return errors.New(\"Any payload is empty; not a valid BytesValue\") }","typeGuard":null,"tryCatchPattern":"v, err := protox.UnpackBytes(anyMsg)\nif err != nil {\n    return fmt.Errorf(\"unpacking %T payload: %w\", anyMsg, err)\n}","preventionTips":["Never hand-assemble Any messages; use PackBytes on the producer side","Avoid transports that may corrupt binary payloads (ensure 8-bit clean encoding)","Validate round-trip: unpack and re-pack in tests"],"tags":["protobuf","unmarshal","go"],"backgroundTag":"protobuf-unmarshal-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}