go data_error ai_generated true

rpc error: code = AlreadyExists desc = user with email '[email protected]' already exists

ID: go/grpc-already-exists-duplicate-resource

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
0Evidence
2025-02-08First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.0+ active — — —

Root Cause

The server rejected a create because a unique constraint (email, ID, etc.) was violated. Often caused by retries without idempotency keys.

generic

中文

服务端因唯一约束(邮箱、ID 等)被违反而拒绝创建。通常由不带幂等键的重试引起。

Workarounds

  1. 90% success
    md := metadata.Pairs("idempotency-key", uuid.NewString())
    ctx := metadata.NewOutgoingContext(ctx, md)
    _, err := client.CreateUser(ctx, req)
  2. 85% success
    if status.Code(err) == codes.AlreadyExists {
      existing, _ := client.GetUser(ctx, &pb.GetUserReq{Email: req.Email})
      return existing, nil
    }

Dead Ends

Common approaches that don't work:

  1. 70% fail

    The existing resource may differ from the intended one; silently accepting hides data bugs

  2. 85% fail

    Creates duplicate logical entities and violates business rules