go
data_error
ai_generated
true
proto: 无法解析无效的 wire-format 数据
proto: cannot parse invalid wire-format data
ID: go/protobuf-unknown-field-error
80%修复率
84%置信度
0证据数
2024-06-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| google.golang.org/protobuf 1.30+ | active | — | — | — |
根因分析
收到的字节不是有效的 protobuf wire format,通常因为客户端与服务端消息类型不一致,或向期待二进制 protobuf 的 gRPC 端点发送了 HTTP/JSON 数据。
English
The received bytes are not a valid protobuf wire format, often because the client and server disagree on the message type, or because HTTP/JSON data was sent to a gRPC endpoint expecting binary protobuf.
解决方案
-
80% 成功率
md, _ := metadata.FromIncomingContext(ctx) log.Printf("content-type=%v len=%d", md.Get("content-type"), len(raw)) if err := proto.Unmarshal(raw, msg); err != nil { return status.Errorf(codes.InvalidArgument, "unmarshal: %v", err) } -
90% 成功率
// pin proto version in go.mod and CI check // go.mod: require github.com/acme/protos v1.4.2 // CI: diff generated files against committed ones
无效尝试
常见但无效的做法:
-
90% 失败
The bytes are malformed, not truncated; increasing the size limit does not make invalid wire format valid.
-
85% 失败
The bytes are binary protobuf, not JSON; protojson will fail with a different parse error.