# rpc error: code = FailedPrecondition desc = resource is not in a valid state for this operation

- **ID:** `go/grpc-failed-precondition-state`
- **Domain:** go
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The server rejected the request because the resource (e.g., database record) is in a state that doesn't allow the operation, such as trying to delete an already deleted item.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.22 | active | — | — |
| 1.23 | active | — | — |

## Workarounds

1. **Check resource state before the RPC and handle accordingly.** (90% success)
   ```
   state, _ := client.GetState(ctx, &pb.GetStateRequest{Id: id})
if state.Status != "active" { return errors.New("cannot perform operation on inactive resource") }
   ```
2. **Use a transactional pattern to ensure state validity.** (85% success)
   ```
   // Implement optimistic locking with version field
req.Version = currentVersion
resp, err := client.UpdateResource(ctx, req)
if status.Code(err) == codes.FailedPrecondition { // retry with fresh version }
   ```

## Dead Ends

- **Retrying the same request immediately.** — Resource state hasn't changed; same error. (90% fail)
- **Ignoring the error and proceeding with other operations.** — May cause data inconsistency; need to handle the state. (80% fail)
