# rpc 错误：代码 = Internal 描述 = 意外错误：运行时错误：索引超出范围

- **ID:** `go/grpc-internal-unexpected-error`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

服务器端发生恐慌或运行时错误，导致内部错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.56.x | active | — | — |
| 1.57.x | active | — | — |

## 解决方案

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

## 无效尝试

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