Skip to content

runtime: PanicNilError error string should have "runtime error: " prefix #63813

Closed

Description

@Goclipse27

What version of Go are you using (go version)?

$ go version
1.21.3

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

Activity

  1. 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
  2. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Oct 29, 2023
  3. mauri870 commented on Oct 29, 2023

    @mauri870
    Member

    This is also confirmed by the Go specification:

    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.

    This behavior was introduced in CL 461956

  4. mauri870 commented on Oct 29, 2023

    @mauri870
    Member

    @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.

  5. gopherbot commented on Oct 29, 2023

    @gopherbot
    Contributor

    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.

  6. mauri870 commented on Oct 29, 2023

    @mauri870
    Member

    Looks like runtime.TypeAssertionError is also a runtime.Error that does not follow this convention.

  7. added a commit that references this issue on Oct 29, 2023
    2ef7eef
  8. self-assigned this
    on Oct 29, 2023
  9. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    and removed
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Oct 29, 2023
  10. gopherbot commented on Oct 30, 2023

    @gopherbot
    Contributor

    Change https://go.dev/cl/538496 mentions this issue: runtime: add missing runtime error prefix to PanicNilError

  11. randall77 commented on Oct 30, 2023

    @randall77
    Contributor

    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:?

  12. added this to the Go1.22 milestone on Nov 1, 2023
  13. added
    NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.
    on Nov 1, 2023
  14. 16 remaining items

  15. added this to the Go1.26 milestone on Aug 12, 2025
  16. odeke-em commented on Dec 7, 2025

    @odeke-em
    Member

    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.

  17. modified the milestones: Go1.26, Go1.27 on Feb 10, 2026
  18. added
    FixPendingIssues that have a fix which has not yet been reviewed or submitted.
    and removed
    NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.
    on Jun 17, 2026
  19. moved this from In Progress to All-But-Submitted in Go Compiler / Runtime / Commandon Jun 17, 2026
  20. added a commit that references this issue on Jun 17, 2026
    16e8e06
  21. gopherbot commented on Jun 17, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/791540 mentions this issue: runtime: prefix "runtime error:" to PanicNilError.Error to fully confirm as runtime.Error

  22. gopherbot commented on Jun 17, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/791700 mentions this issue: cmd/go: adjust test script (fix build)

  23. gopherbot commented on Jun 17, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/791720 mentions this issue: cmd/go/testdata: fix godebug_default.txt with new runtime panic on nil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

FixPendingIssues that have a fix which has not yet been reviewed or submitted.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions