go
data_error
ai_generated
true
rpc 错误:代码 = OutOfRange 描述 = 索引超出界限:10 > 5
rpc error: code = OutOfRange desc = index out of bounds: 10 > 5
ID: go/grpc-out-of-range-index
80%修复率
85%置信度
0证据数
2025-01-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.56.x | active | — | — | — |
| 1.57.x | active | — | — | — |
根因分析
请求尝试访问超出有效范围的元素,例如,分页偏移量过高。
English
A request attempted to access an element beyond the valid range, e.g., pagination offset too high.
解决方案
-
95% 成功率
if offset > totalItems { offset = totalItems } -
90% 成功率
req := &pb.ListRequest{Offset: offset, Limit: limit}; if offset+limit > max { return error } -
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.
100% 失败
Same error will occur.
-
Trying negative values.
80% 失败
Still out of range.
-
Blaming server for incorrect range validation.
50% 失败
Client should respect limits.