diff --git a/errgroup/errgroup.go b/errgroup/errgroup.go index cfafed5..cb6bb9a 100644 --- a/errgroup/errgroup.go +++ b/errgroup/errgroup.go @@ -76,10 +76,8 @@ func (g *Group) Wait() error { } // Go calls the given function in a new goroutine. -// The first call to Go must happen before a Wait. -// It blocks until the new goroutine can be added without the number of -// active goroutines in the group exceeding the configured limit. // +// The first call to Go must happen before a Wait. // It blocks until the new goroutine can be added without the number of // goroutines in the group exceeding the configured limit. // @@ -185,8 +183,9 @@ type PanicError struct { } func (p PanicError) Error() string { - // A Go Error method conventionally does not include a stack dump, so omit it - // here. (Callers who care can extract it from the Stack field.) + if len(p.Stack) > 0 { + return fmt.Sprintf("recovered from errgroup.Group: %v\n%s", p.Recovered, p.Stack) + } return fmt.Sprintf("recovered from errgroup.Group: %v", p.Recovered) } diff --git a/errgroup/errgroup_example_md5all_test.go b/errgroup/errgroup_example_md5all_test.go index 739b336..e2fc15b 100644 --- a/errgroup/errgroup_example_md5all_test.go +++ b/errgroup/errgroup_example_md5all_test.go @@ -8,7 +8,6 @@ import ( "context" "crypto/md5" "fmt" - "io/ioutil" "log" "os" "path/filepath" @@ -69,7 +68,7 @@ func MD5All(ctx context.Context, root string) (map[string][md5.Size]byte, error) for i := 0; i < numDigesters; i++ { g.Go(func() error { for path := range paths { - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { return err } diff --git a/errgroup/errgroup_test.go b/errgroup/errgroup_test.go index 4684259..2165bb7 100644 --- a/errgroup/errgroup_test.go +++ b/errgroup/errgroup_test.go @@ -309,9 +309,9 @@ func TestPanic(t *testing.T) { if pe.Recovered != p { t.Fatalf("got %v, want %v", pe.Recovered, p) } - if !strings.Contains(string(pe.Stack), "TestPanic.func") { - t.Log(string(pe.Stack)) - t.Fatalf("stack trace incomplete") + if !strings.Contains(pe.Error(), "TestPanic.func") { + t.Log(pe.Error()) + t.Fatalf("stack trace incomplete, does not contain TestPanic.func") } }() g.Wait()