go data_error ai_generated true

error: proto: cannot parse invalid wire-format data

ID: go/grpc-protobuf-unmarshal-field-mismatch

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2024-03-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.0 active
1.1 active

Root Cause

The protobuf message received over gRPC has a field with an unexpected wire type, often due to schema mismatch between client and server.

generic

中文

通过gRPC接收的protobuf消息包含一个具有意外线类型的字段,通常是由于客户端和服务器之间的模式不匹配。

Workarounds

  1. 95% success Regenerate Go protobuf code from the same .proto file on both sides.
    protoc --go_out=. --go-grpc_out=. *.proto
  2. 80% success Use protojson format for debugging to identify field type mismatches.
    import "google.golang.org/protobuf/encoding/protojson"
    b, _ := protojson.Marshal(msg)
    log.Printf("%s", b)

Dead Ends

Common approaches that don't work:

  1. Restart both client and server without checking proto files. 90% fail

    The issue is structural mismatch, not transient state.

  2. Update only the client binary without regenerating proto code. 85% fail

    Stale generated code still has old field definitions.