Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace multierror with native errors #115

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/golang/protobuf v1.5.3
github.com/google/go-cmp v0.5.9
github.com/google/pprof v0.0.0-20230426061923-93006964c1fc
github.com/hashicorp/go-multierror v1.1.1
github.com/magefile/mage v1.13.0
github.com/stretchr/testify v1.8.2
google.golang.org/grpc v1.56.3
Expand All @@ -18,7 +17,6 @@ require (
require (
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.23.0 // indirect
Expand Down
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20230426061923-93006964c1fc h1:AGDHt781oIcL4EFk7cPnvBUYTwU8BEU6GDTO3ZMn1sE=
github.com/google/pprof v0.0.0-20230426061923-93006964c1fc/go.mod h1:79YE0hCXdHag9sBkw2o+N/YnZtTkXi0UT9Nnixa5eYk=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down
22 changes: 6 additions & 16 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
package main

import (
"errors"
"fmt"
"os"
"strings"

"github.com/hashicorp/go-multierror"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
Expand Down Expand Up @@ -118,7 +118,7 @@ func (Format) All() {
// License applies the right license header.
func (Format) License() error {
mg.Deps(Prepare.InstallGoLicenser)
return combineErr(
return errors.Join(
sh.RunV("go-licenser", "-license", "Elastic"),
sh.RunV("go-licenser", "-license", "Elastic", "-ext", ".proto"),
)
Expand All @@ -137,25 +137,26 @@ func (Check) GoLint() error {
return err
}

var errs []error
packages := strings.Split(packagesString, "\n")
for _, pkg := range packages {
if strings.Contains(pkg, "/vendor/") {
continue
}

if e := sh.RunV("golint", "-set_exit_status", pkg); e != nil {
err = multierror.Append(err, e)
errs = append(errs, e)
}
}

return err
return errors.Join(errs...)
}

// License makes sure that all the Golang files have the appropriate license header.
func (Check) License() error {
mg.Deps(Prepare.InstallGoLicenser)
// exclude copied files until we come up with a better option
return combineErr(
return errors.Join(
sh.RunV("go-licenser", "-d", "-license", "Elastic"),
)
}
Expand All @@ -171,14 +172,3 @@ func GoInstall(link string) error {
_, err := sh.Exec(map[string]string{}, os.Stdout, os.Stderr, "go", "install", link)
return err
}

func combineErr(errors ...error) error {
var e error
for _, err := range errors {
if err == nil {
continue
}
e = multierror.Append(e, err)
}
return e
}