# rpc错误：代码=无效参数 描述=字段'name'不能为空

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

## 根因

客户端发送的请求包含无效或缺少必填字段，通常是由于缺少验证。

## 版本兼容性

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

## 解决方案

1. **Validate all required fields before making the RPC call.** (90% 成功率)
   ```
   if req.Name == "" {
    return fmt.Errorf("name is required")
}
if req.Age < 0 {
    return fmt.Errorf("age must be non-negative")
}
resp, err := client.SomeRPC(ctx, req)
   ```
2. **Use protobuf validation annotations and generate validation code.** (85% 成功率)
   ```
   In .proto: message MyRequest { string name = 1 [(validate.rules).string.min_len = 1]; }
Then call: if err := req.Validate(); err != nil { return err }
   ```

## 无效尝试

- **Send the request with empty fields again.** — The server will reject it for the same reason. (100% 失败率)
- **Ignore the error and proceed with partial data.** — The RPC failed, so no data was processed. (95% 失败率)
