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

- **ID:** `go/grpc-invalid-argument-enum-value`
- **领域:** go
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.0 | active | — | — |
| 1.1 | active | — | — |

## 解决方案

1. **Ensure the enum value is within the defined set.** (95% 成功率)
   ```
   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. **Use the generated enum constants from protobuf.** (90% 成功率)
   ```
   req.Status = pb.Status_ACTIVE // Use the constant instead of raw integer
   ```

## 无效尝试

- **Ignore the error and assume the server will accept any integer.** — The server validates enum values; invalid ones are rejected. (100% 失败率)
- **Use a random integer within the range hoping it matches.** — Only specific integers are valid enum values; random ones will likely be invalid. (90% 失败率)
