Skip to content

Commit d1ac909

Browse files
qiulaidongfenggopherbot
authored andcommitted
sync/errgroup: PanicError.Error print stack trace
Because it is useful to print the stack when a nil pointer dereference occurs. Fixes golang/go#73710 Change-Id: I106ea0bdd70c2a293f5ea889edef9b5ba9db2fbd Reviewed-on: https://go-review.googlesource.com/c/sync/+/672635 Reviewed-by: Damien Neil <[email protected]> Auto-Submit: Damien Neil <[email protected]> Auto-Submit: Alan Donovan <[email protected]> Reviewed-by: Alan Donovan <[email protected]> TryBot-Bypass: Damien Neil <[email protected]>
1 parent 506c70f commit d1ac909

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

errgroup/errgroup.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,9 @@ type PanicError struct {
185185
}
186186

187187
func (p PanicError) Error() string {
188-
// A Go Error method conventionally does not include a stack dump, so omit it
189-
// here. (Callers who care can extract it from the Stack field.)
188+
if len(p.Stack) > 0 {
189+
return fmt.Sprintf("recovered from errgroup.Group: %v\n%s", p.Recovered, p.Stack)
190+
}
190191
return fmt.Sprintf("recovered from errgroup.Group: %v", p.Recovered)
191192
}
192193

errgroup/errgroup_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,9 @@ func TestPanic(t *testing.T) {
309309
if pe.Recovered != p {
310310
t.Fatalf("got %v, want %v", pe.Recovered, p)
311311
}
312-
if !strings.Contains(string(pe.Stack), "TestPanic.func") {
313-
t.Log(string(pe.Stack))
314-
t.Fatalf("stack trace incomplete")
312+
if !strings.Contains(pe.Error(), "TestPanic.func") {
313+
t.Log(pe.Error())
314+
t.Fatalf("stack trace incomplete, does not contain TestPanic.func")
315315
}
316316
}()
317317
g.Wait()

0 commit comments

Comments
 (0)