go
runtime
ai_generated
true
interface conversion: interface is nil, not T
ID: go/interface-conversion-panic
95%Fix Rate
96%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 121 | active | — | — | — |
Root Cause
Type assertion on a nil interface value.
genericWorkarounds
-
96% success Use the two-value type assertion: val, ok := iface.(T); if !ok { handle }
Safe form doesn't panic; ok is false if assertion fails
Sources: https://go.dev/tour/methods/15
-
90% success Check for nil before type-asserting: if iface != nil { val := iface.(T) }
Nil interfaces always fail type assertions
Dead Ends
Common approaches that don't work:
-
Using recover() globally to catch the panic
75% fail
Masks the nil interface bug; inconsistent state continues
-
Checking for nil after the assertion
85% fail
Panic already happened; nil check is too late
Error Chain
Frequently confused with: