go
data_error
ai_generated
partial
错误:proto:字段"status"具有无效的枚举值:99
error: proto: field "status" has invalid enum value: 99
ID: go/grpc-protobuf-enum-out-of-range
80%修复率
83%置信度
0证据数
2024-05-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.0 | active | — | — | — |
根因分析
protobuf消息包含一个枚举字段,其数值未在.proto文件中定义,通常是由于版本漂移。
English
The protobuf message contains an enum field with a numeric value not defined in the .proto file, often due to version drift.
解决方案
-
90% 成功率 Add the missing enum value to the .proto file and regenerate.
enum Status { UNKNOWN = 0; ACTIVE = 1; INACTIVE = 2; CUSTOM = 99; } -
60% 成功率 Use proto.EnumValueMap to map unknown values to a default.
import "google.golang.org/protobuf/types/known/anypb" // Not directly supported; requires custom unmarshaler
无效尝试
常见但无效的做法:
-
Ignore the error and continue processing.
100% 失败
Unmarshal will fail completely, no partial data.
-
Cast the value to int and treat as unknown.
95% 失败
Protobuf enums are strict; unknown values cause rejection.