# rpc 错误：code = OutOfRange desc = 索引超出范围：10（最大 5）

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

## 根因

客户端提供的参数超出有效范围，例如索引或值超过限制。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   if index >= len(slice) {
    return fmt.Errorf("index %d out of range", index)
}
// Proceed with RPC
   ```
2. **** (90% 成功率)
   ```
   resp, err := client.Method(ctx, req)
if status.Code(err) == codes.OutOfRange {
    // Log and return user-friendly error
    return fmt.Errorf("invalid parameter: %v", err)
}
   ```

## 无效尝试

- **** — This may not be semantically correct and could hide client-side bugs. (70% 失败率)
- **** — The operation will likely fail or produce incorrect results. (90% 失败率)
