# rpc error: code = Internal desc = unexpected error: runtime error: index out of range

- **ID:** `go/grpc-internal-unexpected-error`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A panic or runtime error occurred on the server side, causing an internal error.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.56.x | active | — | — |
| 1.57.x | active | — | — |

## Workarounds

1. **** (80% success)
   ```
   grpc_recovery := grpc_middleware.ChainUnaryServer(grpc_recovery.UnaryServerInterceptor())
   ```
2. **** (95% success)
   ```
   Check for index out of range: if i < len(slice) { ... } else { return status.Error(codes.Internal, "index out of range") }
   ```
3. **** (85% success)
   ```
   Use structured logging: log.WithError(err).Error("internal error")
   ```

## Dead Ends

- **Retrying the same request without changes.** — The server bug will be triggered again. (90% fail)
- **Blaming the client for sending bad data.** — The error is on the server side. (70% fail)
- **Simply restarting the server.** — The bug remains and will occur again. (95% fail)
