go
data_error
ai_generated
true
rpc error: code = AlreadyExists desc = 邮箱为 '[email protected]' 的用户已存在
rpc error: code = AlreadyExists desc = user with email '[email protected]' already exists
ID: go/grpc-already-exists-duplicate-resource
80%修复率
88%置信度
0证据数
2025-02-08首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.0+ | active | — | — | — |
根因分析
服务端因唯一约束(邮箱、ID 等)被违反而拒绝创建。通常由不带幂等键的重试引起。
English
The server rejected a create because a unique constraint (email, ID, etc.) was violated. Often caused by retries without idempotency keys.
解决方案
-
90% 成功率
md := metadata.Pairs("idempotency-key", uuid.NewString()) ctx := metadata.NewOutgoingContext(ctx, md) _, err := client.CreateUser(ctx, req) -
85% 成功率
if status.Code(err) == codes.AlreadyExists { existing, _ := client.GetUser(ctx, &pb.GetUserReq{Email: req.Email}) return existing, nil }
无效尝试
常见但无效的做法:
-
70% 失败
The existing resource may differ from the intended one; silently accepting hides data bugs
-
85% 失败
Creates duplicate logical entities and violates business rules