go data_error ai_generated true

rpc错误:代码=无效参数 描述=字段'status'的枚举值无效:42,期望0-3

rpc error: code = InvalidArgument desc = invalid enum value: 42 for field 'status', expected 0-3

ID: go/grpc-invalid-argument-enum-value

其他格式: JSON · Markdown 中文 · English
80%修复率
88%置信度
0证据数
2025-11-20首次发现

版本兼容性

版本状态引入弃用备注
1.0 active — — —
1.1 active — — —

根因分析

客户端发送了一个整数,该整数不对应protobuf模式中定义的任何有效枚举常量。

English

The client sent an integer value that does not correspond to any valid enum constant defined in the protobuf schema.

generic

解决方案

  1. 95% 成功率 Ensure the enum value is within the defined set.
    validStatuses := map[int32]bool{0: true, 1: true, 2: true, 3: true}
    if !validStatuses[req.Status] {
        return fmt.Errorf("invalid status: %d", req.Status)
    }
  2. 90% 成功率 Use the generated enum constants from protobuf.
    req.Status = pb.Status_ACTIVE // Use the constant instead of raw integer

无效尝试

常见但无效的做法:

  1. Ignore the error and assume the server will accept any integer. 100% 失败

    The server validates enum values; invalid ones are rejected.

  2. Use a random integer within the range hoping it matches. 90% 失败

    Only specific integers are valid enum values; random ones will likely be invalid.