You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
runtime: PanicNilError error string should have "runtime error: " prefix #63813
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
go env Output
$ go env
Windows, amd64, 1.21.3
What did you do?
package main
import (
"fmt"
"runtime"
)
type I interface {
M()
}
func main() {
defer func() {
if r := recover(); r != nil {
if e, ok := r.(runtime.Error); ok {
fmt.Println(e.Error())
}
}
}()
defer func() {
if r := recover(); r != nil {
if e, ok := r.(runtime.Error); ok {
fmt.Println(e.Error())
panic(nil)
}
}
}()
defer func() {
if r := recover(); r != nil {
if e, ok := r.(runtime.Error); ok {
fmt.Println(e.Error())
a := 1
b := 0
fmt.Println(a / b)
}
}
}()
var i I
i.M()
//panic(nil)
//fmt.Println("hello")
}
What did you expect to see?
Since Panic error is a different runtime error as mentioned in the documentation - https://pkg.go.dev/builtin#panic and it has implementation of method - RuntimeError // RuntimeError is a no-op function but // serves to distinguish types that are run time // errors from ordinary errors: a type is a // run time error if it has a RuntimeError method. RuntimeError()
I would like to see the error message like other runtime errors - "runtime error:" as mentioned in the above example
What did you see instead?
I rather the see the error message as - panic called with nil argument
changed the title [-]builtin: PanicNilError : 1.21 - Runtime Error message like Runtime Errors - runtime error: panic called with nil argument[/-][+]runtime: PanicNilError error string should have "runtime error: " prefix[/+]on Oct 29, 2023
The return value of recover is nil when the goroutine is not panicking or recover was not called directly by a deferred function. Conversely, if a goroutine is panicking and recover was called directly by a deferred function, the return value of recover is guaranteed not to be nil. To ensure this, calling panic with a nil interface value (or an untyped nil) causes a run-time panic.
@gopherbot please open a backport issue for Go 1.21.
Errors that implement runtime.Error should have a "runtime error: " prefix, with the solo exception of runtime.plainError on purpose. Calling panic(nil) results in a PanicNilError that violates this constraint.
I think it is past time to update runtime.TypeAssertionError. That's error has been around a long time and is not worth fixing.
(We grandfathered a bunch of errors without the runtime error: prefix using plainError back as part of #14965. This one wasn't so marked, and maybe we can do that, but it would not be a user-visible change I think).
@rsc Do we want to fix PanicNilError to add a runtime error:?
Reacted by Mauri de Souza Meneguzzo and Emmanuel T Odeke
Activity
[-]builtin: PanicNilError : 1.21 - Runtime Error message like Runtime Errors - runtime error: panic called with nil argument[/-][+]runtime: PanicNilError error string should have "runtime error: " prefix[/+]mauri870 commentedon Oct 29, 2023
This is also confirmed by the Go specification:
This behavior was introduced in CL 461956
mauri870 commentedon Oct 29, 2023
@gopherbot please open a backport issue for Go 1.21.
Errors that implement
runtime.Errorshould have a "runtime error: " prefix, with the solo exception of runtime.plainError on purpose. Calling panic(nil) results in a PanicNilError that violates this constraint.gopherbot commentedon Oct 29, 2023
Backport issue(s) opened: #63815 (for 1.21).
Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.
mauri870 commentedon Oct 29, 2023
Looks like
runtime.TypeAssertionErroris also aruntime.Errorthat does not follow this convention.runtime: add missing runtime error prefix to PanicNilError
gopherbot commentedon Oct 30, 2023
Change https://go.dev/cl/538496 mentions this issue:
runtime: add missing runtime error prefix to PanicNilErrorrandall77 commentedon Oct 30, 2023
I think it is past time to update
runtime.TypeAssertionError. That's error has been around a long time and is not worth fixing.(We grandfathered a bunch of errors without the
runtime error:prefix usingplainErrorback as part of #14965. This one wasn't so marked, and maybe we can do that, but it would not be a user-visible change I think).@rsc Do we want to fix
PanicNilErrorto add aruntime error:?16 remaining items
odeke-em commentedon Dec 7, 2025
Kind ping @mauri870, we reviewed and approved the CL https://go-review.googlesource.com/c/go/+/538496 in 2024; kindly please rebase your CL. Thank you.
runtime: prefix "runtime error:" to PanicNilError.Error to fully conf…
gopherbot commentedon Jun 17, 2026
Change https://go.dev/cl/791540 mentions this issue:
runtime: prefix "runtime error:" to PanicNilError.Error to fully confirm as runtime.Errorgopherbot commentedon Jun 17, 2026
Change https://go.dev/cl/791700 mentions this issue:
cmd/go: adjust test script (fix build)gopherbot commentedon Jun 17, 2026
Change https://go.dev/cl/791720 mentions this issue:
cmd/go/testdata: fix godebug_default.txt with new runtime panic on nilcmd/go: adjust test script (fix build)