FAILED_PRECONDITION
gRPCERRORNotableServer-SideHIGH confidence

The operation was rejected because the system is not in a state required for the operation's execution

What this means

Indicates the system is not in the required state for the requested operation. For example, trying to delete a non-empty directory. This is not a client error.

Why it happens
  1. 1Attempting to perform an action on a resource that is in the wrong state (e.g., deleting a user that is still active).
  2. 2A required initialization step has not been completed on the server.
  3. 3Running a command that depends on another process that is not currently running.
How to reproduce

A client tries to delete a project before all resources within it have been deleted.

trigger — this will error
trigger — this will error
// Client tries to delete a directory that is not empty
try {
  await client.deleteDirectory({ path: "/usr/data" });
} catch (e) {
  // e.code is FAILED_PRECONDITION if directory is not empty
}

expected output

StatusCode.FAILED_PRECONDITION: The operation was rejected because the system is not in a state required for the operation's execution

Fix 1

Perform the Prerequisite Actions

WHEN The required state is achievable by the client.

Perform the Prerequisite Actions
// First, delete the files in the directory
await client.deleteFile({ path: "/usr/data/file1.txt" });
// Then, delete the directory itself
await client.deleteDirectory({ path: "/usr/data" });

Why this works

Execute the sequence of operations required to put the system into the correct state before retrying the failed call.

Fix 2

Check System State Before Acting

WHEN To avoid making a call that is guaranteed to fail.

Check System State Before Acting
const dir = await client.getDirectory({ path: "/usr/data" });
if (dir.isEmpty) {
  await client.deleteDirectory({ path: "/usr/data" });
} else {
  reportError("Directory must be empty before deletion.");
}

Why this works

Proactively query the system's state to ensure preconditions are met before attempting a state-changing operation.

What not to do

Retry the request without changing the system state

This error is deterministic based on the current system state. The request will continue to fail until the prerequisite condition is met.

Sources

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

← All gRPC errors