go data_error ai_generated true

rpc error: code = OutOfRange desc = index out of bounds: 10 > 5

ID: go/grpc-out-of-range-index

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2025-01-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.56.x active
1.57.x active

Root Cause

A request attempted to access an element beyond the valid range, e.g., pagination offset too high.

generic

中文

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

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. Retrying with the same out-of-range index. 100% fail

    Same error will occur.

  2. Trying negative values. 80% fail

    Still out of range.

  3. Blaming server for incorrect range validation. 50% fail

    Client should respect limits.