Skip to content

Commit

Permalink
feat: dedup final errors based on the message
Browse files Browse the repository at this point in the history
  • Loading branch information
femnad committed Dec 21, 2023
1 parent a2e380d commit dd05612
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

const (
version = "0.21.2"
version = "0.22.0"
)

type args struct {
Expand Down Expand Up @@ -59,7 +59,7 @@ func main() {

err = p.Apply()
if err != nil {
fmt.Printf("Some provisioners had errors: %v\n", err)
fmt.Printf("Some provisioners had errors:\n%v\n", err)
os.Exit(1)
}
}
13 changes: 12 additions & 1 deletion provision/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,18 @@ func (p provisioners) apply() error {
provErrs = append(provErrs, err)
}

return errors.Join(provErrs...)
var uniqErrs []error
seenErr := make(map[string]error)
for _, err := range provErrs {
msg := err.Error()
_, ok := seenErr[msg]
if !ok {
seenErr[msg] = err
uniqErrs = append(uniqErrs, err)
}
}

return errors.Join(uniqErrs...)
}

func newProvisioners(allProvisioners []provisionFn, filter []string) (provisioners, error) {
Expand Down

0 comments on commit dd05612

Please sign in to comment.