mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: do not print recovered when double panic with the same value
Show the "[recovered, repanicked]" message only when it is repanicked after recovered. For the duplicated panics that not recovered, do not show this message. Fixes #76099 Change-Id: I87282022ebe44c6f6efbe3239218be4a2a7b1104 Reviewed-on: https://go-review.googlesource.com/c/go/+/716020 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Junyang Shao <shaojunyang@google.com> Auto-Submit: Michael Pratt <mpratt@google.com>
This commit is contained in:
parent
9859b43643
commit
c93766007d
3 changed files with 21 additions and 1 deletions
|
|
@ -413,6 +413,15 @@ func TestRepanickedPanicSandwich(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDoublePanicWithSameValue(t *testing.T) {
|
||||||
|
output := runTestProg(t, "testprog", "DoublePanicWithSameValue")
|
||||||
|
want := `panic: message
|
||||||
|
`
|
||||||
|
if !strings.HasPrefix(output, want) {
|
||||||
|
t.Fatalf("output does not start with %q:\n%s", want, output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGoexitCrash(t *testing.T) {
|
func TestGoexitCrash(t *testing.T) {
|
||||||
// External linking brings in cgo, causing deadlock detection not working.
|
// External linking brings in cgo, causing deadlock detection not working.
|
||||||
testenv.MustInternalLink(t, deadlockBuildTypes)
|
testenv.MustInternalLink(t, deadlockBuildTypes)
|
||||||
|
|
|
||||||
|
|
@ -739,7 +739,7 @@ func printpanics(p *_panic) {
|
||||||
}
|
}
|
||||||
print("panic: ")
|
print("panic: ")
|
||||||
printpanicval(p.arg)
|
printpanicval(p.arg)
|
||||||
if p.repanicked {
|
if p.recovered && p.repanicked {
|
||||||
print(" [recovered, repanicked]")
|
print(" [recovered, repanicked]")
|
||||||
} else if p.recovered {
|
} else if p.recovered {
|
||||||
print(" [recovered]")
|
print(" [recovered]")
|
||||||
|
|
|
||||||
11
src/runtime/testdata/testprog/crash.go
vendored
11
src/runtime/testdata/testprog/crash.go
vendored
|
|
@ -22,6 +22,7 @@ func init() {
|
||||||
register("RepanickedPanic", RepanickedPanic)
|
register("RepanickedPanic", RepanickedPanic)
|
||||||
register("RepanickedMiddlePanic", RepanickedMiddlePanic)
|
register("RepanickedMiddlePanic", RepanickedMiddlePanic)
|
||||||
register("RepanickedPanicSandwich", RepanickedPanicSandwich)
|
register("RepanickedPanicSandwich", RepanickedPanicSandwich)
|
||||||
|
register("DoublePanicWithSameValue", DoublePanicWithSameValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func test(name string) {
|
func test(name string) {
|
||||||
|
|
@ -189,3 +190,13 @@ func RepanickedPanicSandwich() {
|
||||||
panic("outer")
|
panic("outer")
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Double panic with same value and not recovered.
|
||||||
|
// See issue 76099.
|
||||||
|
func DoublePanicWithSameValue() {
|
||||||
|
var e any = "message"
|
||||||
|
defer func() {
|
||||||
|
panic(e)
|
||||||
|
}()
|
||||||
|
panic(e)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue