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 <dneil@google.com> Auto-Submit: Damien Neil <dneil@google.com> Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> TryBot-Bypass: Damien Neil <dneil@google.com>
This commit is contained in:
parent
506c70f973
commit
d1ac909e84
2 changed files with 6 additions and 5 deletions
|
|
@ -185,8 +185,9 @@ type PanicError struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p PanicError) Error() string {
|
func (p PanicError) Error() string {
|
||||||
// A Go Error method conventionally does not include a stack dump, so omit it
|
if len(p.Stack) > 0 {
|
||||||
// here. (Callers who care can extract it from the Stack field.)
|
return fmt.Sprintf("recovered from errgroup.Group: %v\n%s", p.Recovered, p.Stack)
|
||||||
|
}
|
||||||
return fmt.Sprintf("recovered from errgroup.Group: %v", p.Recovered)
|
return fmt.Sprintf("recovered from errgroup.Group: %v", p.Recovered)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -309,9 +309,9 @@ func TestPanic(t *testing.T) {
|
||||||
if pe.Recovered != p {
|
if pe.Recovered != p {
|
||||||
t.Fatalf("got %v, want %v", pe.Recovered, p)
|
t.Fatalf("got %v, want %v", pe.Recovered, p)
|
||||||
}
|
}
|
||||||
if !strings.Contains(string(pe.Stack), "TestPanic.func") {
|
if !strings.Contains(pe.Error(), "TestPanic.func") {
|
||||||
t.Log(string(pe.Stack))
|
t.Log(pe.Error())
|
||||||
t.Fatalf("stack trace incomplete")
|
t.Fatalf("stack trace incomplete, does not contain TestPanic.func")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
g.Wait()
|
g.Wait()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue