go
data_error
ai_generated
true
rpc error: code = OutOfRange desc = index 10 out of bounds for list of length 5
ID: go/grpc-out-of-range-index-error
80%Fix Rate
86%Confidence
0Evidence
2024-12-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.0 | active | — | — | — |
| 1.1 | active | — | — | — |
Root Cause
Client requested an index that exceeds the size of a list or array in the response.
generic中文
客户端请求的索引超出了响应中列表或数组的大小。
Workarounds
-
95% success Validate the index before making the request.
if idx < 0 || idx >= len(items) { return fmt.Errorf("index out of range") } resp, err := client.GetItem(ctx, &pb.GetRequest{Index: int32(idx)}) -
90% success Fetch the entire list and then access the index locally.
listResp, err := client.GetList(ctx, &pb.ListRequest{}) if err != nil { return err } if idx < 0 || idx >= len(listResp.Items) { return fmt.Errorf("index out of range") } item := listResp.Items[idx]
Dead Ends
Common approaches that don't work:
-
Assume the server will handle out-of-range gracefully.
100% fail
The server returns an error; it does not auto-correct.
-
Use negative indexing hoping it wraps around.
90% fail
Protobuf does not support negative indexing; it will still fail.