Skip to content

Commit

Permalink
refactor makeStr
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-87 committed Nov 2, 2023
1 parent 9d2f513 commit d818876
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions errsizedgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package syncs
import (
"context"
"fmt"
"strings"
"sync"
)

Expand Down Expand Up @@ -119,7 +120,6 @@ func (g *ErrSizedGroup) Go(f func(ctx context.Context) error) {
// returns all errors (if any) wrapped with multierror from them.
func (g *ErrSizedGroup) Wait() error {
g.wg.Wait()
g.err.makeStr()
return g.err.ErrorOrNil()
}

Expand All @@ -135,6 +135,7 @@ func (m *MultiError) ErrorOrNil() error {
if m.len() == 0 {
return nil
}
m.makeStr()
return m
}

Expand All @@ -161,15 +162,11 @@ func (m *MultiError) len() int {
}

func (m *MultiError) makeStr() {
lenErrors := m.len()
if lenErrors == 0 {
return
}
errs := fmt.Sprintf("[0] {%s}", m.Errors()[0].Error())
if lenErrors > 1 {
for n, e := range m.Errors()[1:] {
errs += fmt.Sprintf(", [%d] {%s}", n+1, e.Error())
}
lenErrors := len(m.errors)
m.str = fmt.Sprintf("%d error(s) occurred: ", lenErrors)
errs := make([]string, lenErrors)
for i := range m.errors {
errs[i] = fmt.Sprintf("[%d] {%s}", i, m.errors[i])
}
m.str = fmt.Sprintf("%d error(s) occurred: %s", lenErrors, errs)
m.str += strings.Join(errs, ", ")
}

0 comments on commit d818876

Please sign in to comment.