go
runtime_error
ai_generated
true
panic: runtime error: index out of range [3] with length 2 (in goroutine)
ID: go/goroutine-panic-unrecovered
80%Fix Rate
84%Confidence
0Evidence
2024-10-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.21 | active | — | — | — |
Root Cause
goroutine中访问了超出切片范围的索引,导致panic。
generic中文
goroutine中访问了超出切片范围的索引,导致panic。
Workarounds
-
90% success
if i < len(slice) { v := slice[i] } -
85% success
go func(){ defer func(){ if r := recover(); r != nil { log.Println(r) } }(); /* ... */ }()
Dead Ends
Common approaches that don't work:
-
60% fail
检查不充分,可能仍有边界情况。
-
70% fail
recover只能恢复,但数据可能未处理。