ALREADY_EXISTS
gRPCERRORCommonClient-SideHIGH confidence

An attempt to create an entity failed because it already exists

What this means

Indicates that a client tried to create a resource that already exists. This is a client-side error, and the client should not retry the creation.

Why it happens
  1. 1The client is trying to create a resource with an ID that is already in use.
  2. 2A previous request to create the same resource succeeded, but the client retried due to a network error.
  3. 3A race condition where two clients attempt to create the same resource simultaneously.
How to reproduce

A client attempts to create a new user with an email address that is already registered.

trigger — this will error
trigger — this will error
// Client attempts to create a user with an existing ID
try {
  await client.createUser({ userId: "existing-user-456", name: "Jane Doe" });
} catch (e) {
  // e.code will be grpc.status.ALREADY_EXISTS
}

expected output

StatusCode.ALREADY_EXISTS: An attempt to create an entity failed because it already exists

Fix 1

Implement 'Get-or-Create' Logic

WHEN When the client's intent is to ensure the resource exists.

Implement 'Get-or-Create' Logic
try {
  await client.createUser(request);
} catch (e) {
  if (e.code === grpc.status.ALREADY_EXISTS) {
    // It already exists, which is fine. Fetch it.
    return await client.getUser({ userId: request.userId });
  }
  throw e;
}

Why this works

Treating ALREADY_EXISTS as a successful outcome for a creation request makes the operation idempotent.

Fix 2

Provide User Feedback

WHEN When creating a resource via a user interface.

Provide User Feedback
// In the UI, after catching ALREADY_EXISTS
displayErrorMessage("A user with this ID already exists. Please choose a different ID.");

Why this works

Inform the user that their chosen identifier is already taken so they can correct it.

What not to do

✕ Retry the creation request without modification

The resource already exists. Retrying the creation will fail every time and is a logical error.

Sources

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All gRPC errors