From 620aaaacc18e01ec375592b280997a4016778ac2 Mon Sep 17 00:00:00 2001 From: Jon Johnson Date: Tue, 2 Jan 2024 09:21:32 -0800 Subject: [PATCH] Drop multierror for errgroup This should be functionally equivalent but drops the multierror dependency. Signed-off-by: Jon Johnson --- go.mod | 2 -- go.sum | 5 ----- pkg/build/build.go | 23 +++++++++++++++++------ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index fb05cbf6f..6139d7eb9 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,6 @@ require ( github.com/google/go-cmp v0.6.0 github.com/google/go-containerregistry v0.16.1 github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 - github.com/hashicorp/go-multierror v1.1.1 github.com/invopop/jsonschema v0.12.0 github.com/jinzhu/copier v0.4.0 github.com/klauspost/pgzip v1.2.6 @@ -68,7 +67,6 @@ require ( github.com/go-openapi/validate v0.22.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect - github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-retryablehttp v0.7.4 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect diff --git a/go.sum b/go.sum index 75c27dc1f..56c12c54f 100644 --- a/go.sum +++ b/go.sum @@ -165,15 +165,10 @@ github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3 github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -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-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI= github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= -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/hashicorp/go-retryablehttp v0.7.4 h1:ZQgVdpTdAL7WpMIwLzCfbalOcSUdkDZnpUv3/+BxzFA= github.com/hashicorp/go-retryablehttp v0.7.4/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= diff --git a/pkg/build/build.go b/pkg/build/build.go index 484a12bca..31068b9b6 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -18,6 +18,7 @@ import ( "compress/gzip" "context" "encoding/hex" + "errors" "fmt" "io" "os" @@ -30,8 +31,8 @@ import ( apkfs "github.com/chainguard-dev/go-apk/pkg/fs" v1 "github.com/google/go-containerregistry/pkg/v1" v1types "github.com/google/go-containerregistry/pkg/v1/types" - "github.com/hashicorp/go-multierror" "go.opentelemetry.io/otel" + "golang.org/x/sync/errgroup" "gopkg.in/yaml.v3" "chainguard.dev/apko/pkg/build/types" @@ -160,14 +161,24 @@ func (bc *Context) ImageLayoutToLayer(ctx context.Context) (string, v1.Layer, er } func (bc *Context) runAssertions() error { - var eg multierror.Group + errs := make([]error, len(bc.assertions)) - for _, a := range bc.assertions { - a := a - eg.Go(func() error { return a(bc) }) + var eg errgroup.Group + for i, a := range bc.assertions { + i, a := i, a + eg.Go(func() error { + errs[i] = a(bc) + + // We don't want to fail early. + return nil + }) + } + + if err := eg.Wait(); err != nil { + return err } - return eg.Wait().ErrorOrNil() + return errors.Join(errs...) } // NewOptions evaluates the build.Options in the same way as New().