go
type_error
ai_generated
true
rpc错误:代码=无效参数 描述=无效字段:name:值为空,必须是非空字符串
rpc error: code = InvalidArgument desc = invalid field: name: value is empty, must be a non-empty string
ID: go/grpc-invalid-argument-missing-field
80%修复率
87%置信度
0证据数
2024-04-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.22 | active | — | — | — |
| 1.23 | active | — | — | — |
根因分析
客户端发送的protobuf消息中必填字段为空或无效,违反了服务器端验证规则。
English
The client sent a protobuf message with a required field left empty or invalid, violating server-side validation rules.
解决方案
-
95% 成功率 Validate all required fields before sending the RPC.
if req.Name == "" { return errors.New("name must not be empty") } resp, err := client.CreateUser(ctx, req) -
90% 成功率 Use protovalidate library to enforce constraints client-side.
import "github.com/bufbuild/protovalidate-go" validator, _ := protovalidate.New() if err := validator.Validate(req); err != nil { return err }
无效尝试
常见但无效的做法:
-
Ignoring the error and resending the same message.
100% 失败
The message is still invalid; error will repeat.
-
Setting the field to a random non-empty string without understanding the requirement.
80% 失败
May cause data corruption or further validation errors.