# rpc 错误：代码 = OutOfRange 描述 = 索引超出界限：10 > 5

- **ID:** `go/grpc-out-of-range-index`
- **领域:** go
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

请求尝试访问超出有效范围的元素，例如，分页偏移量过高。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   if offset > totalItems { offset = totalItems }
   ```
2. **** (90% 成功率)
   ```
   req := &pb.ListRequest{Offset: offset, Limit: limit}; if offset+limit > max { return error }
   ```
3. **** (85% 成功率)
   ```
   resp, err := client.List(ctx, req); if resp.TotalCount > 0 { offset = min(offset, resp.TotalCount-1) }
   ```

## 无效尝试

- **Retrying with the same out-of-range index.** — Same error will occur. (100% 失败率)
- **Trying negative values.** — Still out of range. (80% 失败率)
- **Blaming server for incorrect range validation.** — Client should respect limits. (50% 失败率)
