diff options
| author | Damien Neil <dneil@google.com> | 2025-01-31 15:03:15 -0800 |
|---|---|---|
| committer | Damien Neil <dneil@google.com> | 2025-02-06 12:02:14 -0800 |
| commit | 478ad013f90fe1dbb199d22f41b93c920ae0d5e9 (patch) | |
| tree | 9baaa33c1515d4048dc431d5801aec34e213da1b /src/runtime/panic.go | |
| parent | 9b4a462a7d85753738723402e298039c3424e584 (diff) | |
| download | go-478ad013f90fe1dbb199d22f41b93c920ae0d5e9.tar.xz | |
runtime: don't duplicate reraised panic values in printpanics
Change the output printed when crashing with a reraised panic value
to not duplicate that value.
Changes output of panicking with "PANIC", recovering, and reraising
from:
panic: PANIC [recovered]
panic: PANIC
to:
panic: PANIC [recovered, reraised]
Fixes #71517
Change-Id: Id59938c4ea0df555b851ffc650fe6f94c0845499
Reviewed-on: https://go-review.googlesource.com/c/go/+/645916
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/runtime/panic.go')
| -rw-r--r-- | src/runtime/panic.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/runtime/panic.go b/src/runtime/panic.go index 3ffb3966d0..2dd3c3c2db 100644 --- a/src/runtime/panic.go +++ b/src/runtime/panic.go @@ -649,6 +649,13 @@ func preprintpanics(p *_panic) { } }() for p != nil { + if p.link != nil && *efaceOf(&p.link.arg) == *efaceOf(&p.arg) { + // This panic contains the same value as the next one in the chain. + // Mark it as reraised. We will skip printing it twice in a row. + p.link.reraised = true + p = p.link + continue + } switch v := p.arg.(type) { case error: p.arg = v.Error() @@ -664,6 +671,9 @@ func preprintpanics(p *_panic) { func printpanics(p *_panic) { if p.link != nil { printpanics(p.link) + if p.link.reraised { + return + } if !p.link.goexit { print("\t") } @@ -673,7 +683,9 @@ func printpanics(p *_panic) { } print("panic: ") printpanicval(p.arg) - if p.recovered { + if p.reraised { + print(" [recovered, reraised]") + } else if p.recovered { print(" [recovered]") } print("\n") |
