Skip to content

Commit 24b436f

Browse files
committed
refactor: replace multierror with native errors
Go 1.20 added support for wrapping multiple errors. Drop multierror library and use stdlib errors
1 parent 4d41e73 commit 24b436f

3 files changed

Lines changed: 6 additions & 23 deletions

File tree

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ require (
88
github.com/golang/protobuf v1.5.3
99
github.com/google/go-cmp v0.5.9
1010
github.com/google/pprof v0.0.0-20230426061923-93006964c1fc
11-
github.com/hashicorp/go-multierror v1.1.1
1211
github.com/magefile/mage v1.13.0
1312
github.com/stretchr/testify v1.8.2
1413
golang.org/x/exp v0.0.0-20231127185646-65229373498e
@@ -19,7 +18,6 @@ require (
1918
require (
2019
github.com/Microsoft/go-winio v0.5.2 // indirect
2120
github.com/davecgh/go-spew v1.1.1 // indirect
22-
github.com/hashicorp/errwrap v1.1.0 // indirect
2321
github.com/kr/text v0.2.0 // indirect
2422
github.com/pmezard/go-difflib v1.0.0 // indirect
2523
golang.org/x/net v0.23.0 // indirect

go.sum

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
1616
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
1717
github.com/google/pprof v0.0.0-20230426061923-93006964c1fc h1:AGDHt781oIcL4EFk7cPnvBUYTwU8BEU6GDTO3ZMn1sE=
1818
github.com/google/pprof v0.0.0-20230426061923-93006964c1fc/go.mod h1:79YE0hCXdHag9sBkw2o+N/YnZtTkXi0UT9Nnixa5eYk=
19-
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
20-
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
21-
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
22-
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
23-
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
2419
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
2520
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
2621
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=

magefile.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
package main
99

1010
import (
11+
"errors"
1112
"fmt"
1213
"os"
1314
"strings"
1415

15-
"github.com/hashicorp/go-multierror"
1616
"github.com/magefile/mage/mg"
1717
"github.com/magefile/mage/sh"
1818
)
@@ -118,7 +118,7 @@ func (Format) All() {
118118
// License applies the right license header.
119119
func (Format) License() error {
120120
mg.Deps(Prepare.InstallGoLicenser)
121-
return combineErr(
121+
return errors.Join(
122122
sh.RunV("go-licenser", "-license", "Elastic"),
123123
sh.RunV("go-licenser", "-license", "Elastic", "-ext", ".proto"),
124124
)
@@ -137,25 +137,26 @@ func (Check) GoLint() error {
137137
return err
138138
}
139139

140+
var errs []error
140141
packages := strings.Split(packagesString, "\n")
141142
for _, pkg := range packages {
142143
if strings.Contains(pkg, "/vendor/") {
143144
continue
144145
}
145146

146147
if e := sh.RunV("golint", "-set_exit_status", pkg); e != nil {
147-
err = multierror.Append(err, e)
148+
errs = append(errs, e)
148149
}
149150
}
150151

151-
return err
152+
return errors.Join(errs...)
152153
}
153154

154155
// License makes sure that all the Golang files have the appropriate license header.
155156
func (Check) License() error {
156157
mg.Deps(Prepare.InstallGoLicenser)
157158
// exclude copied files until we come up with a better option
158-
return combineErr(
159+
return errors.Join(
159160
sh.RunV("go-licenser", "-d", "-license", "Elastic"),
160161
)
161162
}
@@ -171,14 +172,3 @@ func GoInstall(link string) error {
171172
_, err := sh.Exec(map[string]string{}, os.Stdout, os.Stderr, "go", "install", link)
172173
return err
173174
}
174-
175-
func combineErr(errors ...error) error {
176-
var e error
177-
for _, err := range errors {
178-
if err == nil {
179-
continue
180-
}
181-
e = multierror.Append(e, err)
182-
}
183-
return e
184-
}

0 commit comments

Comments
 (0)