{"record":{"id":"c3f3f8da3117e4c4","repo":"apache/beam","slug":"bad-type-v-want-v","errorCode":null,"errorMessage":"bad type: %v, want %v","messagePattern":"bad type: (.+?), want (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/protox/any.go","lineNumber":32,"sourceCode":"// limitations under the License.\n\npackage protox\n\nimport (\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/internal/errors\"\n\t\"google.golang.org/protobuf/proto\"\n\tprotobuf \"google.golang.org/protobuf/types/known/anypb\"\n\tprotobufw \"google.golang.org/protobuf/types/known/wrapperspb\"\n)\n\nconst (\n\tbytesValueTypeURL = \"type.googleapis.com/google.protobuf.BytesValue\"\n)\n\n// Unpack decodes a proto.\nfunc Unpack(data *protobuf.Any, url string, ret proto.Message) error {\n\tif data.TypeUrl != url {\n\t\treturn errors.Errorf(\"bad type: %v, want %v\", data.TypeUrl, url)\n\t}\n\treturn proto.Unmarshal(data.Value, ret)\n}\n\n// UnpackProto decodes a BytesValue wrapped proto.\nfunc UnpackProto(data *protobuf.Any, ret proto.Message) error {\n\tbuf, err := UnpackBytes(data)\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn proto.Unmarshal(buf, ret)\n}\n\n// PackProto encodes a proto message and wraps into a BytesValue.\nfunc PackProto(in proto.Message) (*protobuf.Any, error) {\n\tb, err := proto.Marshal(in)\n\tif err != nil {\n\t\treturn nil, err","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/protox/any.go#L14-L50","documentation":"protox.Unpack verifies that the Any proto's TypeUrl matches the expected url before unmarshaling its payload into ret. If they differ it returns this error without touching ret, preventing unmarshaling bytes of the wrong message type into the caller's message.","triggerScenarios":"Calling protox.Unpack(data, url, ret) where data.TypeUrl != url — e.g. unpacking an Any produced by protox.PackProto (BytesValue wrapper, url \"type.googleapis.com/google.protobuf.BytesValue\") with Unpack, or passing the wrong expected URL for the serialized message.","commonSituations":"Mixing Unpack and UnpackProto: data was packed with PackProto but unpacked without the BytesValue type URL; sender upgraded/repacked the payload with a different message type; hard-coded URL string that doesn't match the proto package path of the actual message.","solutions":["Make the expected url match how the Any was created: use protox.UnpackProto for payloads packed via PackProto, or pass bytesValueTypeURL to Unpack","Use protox.Pack/Unpack pairs consistently on sender and receiver (Pack with the same message type and URL)","Log data.TypeUrl on failure and compare against the constant you pass; fix the constant or the packing side","Regenerate/republish the payload if the producer switched message types"],"exampleFix":"// before\nvar req pb.MyRequest\nprotox.Unpack(data, \"type.googleapis.com/MyRequest\", &req) // TypeUrl is BytesValue\n// after\nvar wrapped pb.BytesValue\nprotox.UnpackProto(data, &wrapped) // or protox.Unpack(data, protox.BytesValueTypeURL, &wrapped)\nvar req pb.MyRequest\nproto.Unmarshal(wrapped.Value, &req)","handlingStrategy":"type-guard","validationCode":"// verify the Any carries the expected URL before unpacking\nif data.GetTypeUrl() != \"type.googleapis.com/google.protobuf.BytesValue\" {\n    return fmt.Errorf(\"unexpected payload type: %s\", data.GetTypeUrl())\n}","typeGuard":"func isBytesValueAny(data *anypb.Any) bool {\n    return data.GetTypeUrl() == \"type.googleapis.com/google.protobuf.BytesValue\"\n}","tryCatchPattern":"if err := protox.Unpack(data, url, msg); err != nil {\n    if strings.HasPrefix(err.Error(), \"bad type:\") {\n        return fmt.Errorf(\"payload type mismatch: got %s, want %s\", data.GetTypeUrl(), url)\n    }\n    return err\n}","preventionTips":["Pair pack/unpack helpers consistently: Pack with Unpack, PackProto with UnpackProto","Derive the URL from protox constants (e.g. bytesValueTypeURL) instead of hand-written strings","Include the message type/URL in serialized envelopes so receivers can verify before unmarshaling","Log data.TypeUrl in wrapped errors to speed up diagnosing producer/consumer drift"],"tags":["go","protobuf","type-mismatch","beam"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}