From a37d08ae8776f93d6c0b1480f50268c629cbb6b8 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Mon, 12 Aug 2024 15:43:58 +0100 Subject: [PATCH] remove multierror package --- broker.go | 22 ++++++++++------------ broker_test.go | 17 ++++++++++------- go.mod | 2 -- go.sum | 5 ----- graph.go | 15 +++++++-------- 5 files changed, 27 insertions(+), 34 deletions(-) diff --git a/broker.go b/broker.go index d0a5716..2da2999 100644 --- a/broker.go +++ b/broker.go @@ -9,8 +9,6 @@ import ( "fmt" "sync" "time" - - "github.com/hashicorp/go-multierror" ) // RegistrationPolicy is used to specify what kind of policy should apply when @@ -434,7 +432,7 @@ func (b *Broker) RemovePipeline(t EventType, id PipelineID) error { // neither the pipeline nor nodes will be deleted. // // Once we start deleting the pipeline and nodes, we will continue until completion, -// but we'll return true along with any errors encountered (as multierror.Error). +// but we'll return true along with any errors encountered. func (b *Broker) RemovePipelineAndNodes(ctx context.Context, t EventType, id PipelineID) (bool, error) { switch { case t == "": @@ -458,16 +456,16 @@ func (b *Broker) RemovePipelineAndNodes(ctx context.Context, t EventType, id Pip g.roots.Delete(id) - var nodeErr error + var nodeErrs []error for _, nodeID := range nodes { err = b.removeNode(ctx, nodeID, true) if err != nil { - nodeErr = multierror.Append(nodeErr, err) + nodeErrs = append(nodeErrs, err) } } - return true, nodeErr + return true, errors.Join(nodeErrs...) } // SetSuccessThreshold sets the success threshold per EventType. For the @@ -579,26 +577,26 @@ func (b *Broker) IsAnyPipelineRegistered(e EventType) bool { // validate ensures that the Pipeline has the required configuration to allow // registration, removal or usage, without issue. func (p Pipeline) validate() error { - var err error + var errs []error if p.PipelineID == "" { - err = multierror.Append(err, errors.New("pipeline ID is required")) + errs = append(errs, fmt.Errorf("pipeline ID is required")) } if p.EventType == "" { - err = multierror.Append(err, errors.New("event type is required")) + errs = append(errs, fmt.Errorf("event type is required")) } if len(p.NodeIDs) == 0 { - err = multierror.Append(err, errors.New("node IDs are required")) + errs = append(errs, fmt.Errorf("node IDs are required")) } for _, n := range p.NodeIDs { if n == "" { - err = multierror.Append(err, errors.New("node ID cannot be empty")) + errs = append(errs, fmt.Errorf("node ID cannot be empty")) break } } - return err + return errors.Join(errs...) } diff --git a/broker_test.go b/broker_test.go index ee8334e..2b88405 100644 --- a/broker_test.go +++ b/broker_test.go @@ -14,7 +14,6 @@ import ( "time" "github.com/go-test/deep" - "github.com/hashicorp/go-multierror" "github.com/hashicorp/go-uuid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -475,9 +474,10 @@ func TestRemovePipelineAndNodes(t *testing.T) { ok, err = broker.RemovePipelineAndNodes(ctx, EventType("t"), "p2") require.Error(t, err) require.True(t, ok) - me, ok := err.(*multierror.Error) + unwrapped, ok := err.(interface{ Unwrap() []error }) require.True(t, ok) - require.Equal(t, 2, me.Len()) + errs := unwrapped.Unwrap() + require.Len(t, errs, 2) } // TestRemovePipelineAndNodes_BadEventType tests attempting to remove a pipeline @@ -561,9 +561,11 @@ func TestRegisterPipeline_BadParameters(t *testing.T) { }) require.Error(t, err) - me, ok := err.(*multierror.Error) + unwrapped, ok := err.(interface{ Unwrap() []error }) require.True(t, ok) - require.EqualError(t, me.Unwrap(), tc.error) + errs := unwrapped.Unwrap() + require.Len(t, errs, 1) + require.EqualError(t, errs[0], tc.error) }) } } @@ -692,9 +694,10 @@ func TestPipelineValidate(t *testing.T) { require.NoError(t, err) default: require.Error(t, err) - me, ok := err.(*multierror.Error) + unwrapped, ok := err.(interface{ Unwrap() []error }) require.True(t, ok) - require.Equal(t, tc.expectErrorCount, me.Len()) + errs := unwrapped.Unwrap() + require.Len(t, errs, tc.expectErrorCount) } }) } diff --git a/go.mod b/go.mod index 0715629..b9fe129 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ go 1.23.0 require ( github.com/go-test/deep v1.1.1 - github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/go-secure-stdlib/base62 v0.1.2 github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 github.com/hashicorp/go-uuid v1.0.3 @@ -16,7 +15,6 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/google/go-cmp v0.6.0 // indirect - github.com/hashicorp/errwrap v1.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/ryanuber/go-glob v1.0.0 // indirect golang.org/x/mod v0.24.0 // indirect diff --git a/go.sum b/go.sum index def4084..56f7356 100644 --- a/go.sum +++ b/go.sum @@ -6,11 +6,6 @@ github.com/go-test/deep v1.1.1 h1:0r/53hagsehfO4bzD2Pgr/+RgHqhmf+k1Bpse2cTu1U= github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -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/hashicorp/go-secure-stdlib/base62 v0.1.2 h1:ET4pqyjiGmY09R5y+rSd70J2w45CtbWDNvGqWp/R3Ng= github.com/hashicorp/go-secure-stdlib/base62 v0.1.2/go.mod h1:EdWO6czbmthiwZ3/PUsDV+UD1D5IRU4ActiaWGwt0Yw= github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 h1:kes8mmyCpxJsI7FTwtzRqEy9CdjCtrXrXGuOpxEA7Ts= diff --git a/graph.go b/graph.go index 2915381..82ae53f 100644 --- a/graph.go +++ b/graph.go @@ -5,10 +5,9 @@ package eventlogger import ( "context" + "errors" "fmt" "sync" - - "github.com/hashicorp/go-multierror" ) // graph @@ -129,17 +128,17 @@ func (g *graph) doProcess(ctx context.Context, node *linkedNode, e *Event, statu } func (g *graph) reopen(ctx context.Context) error { - var errors *multierror.Error + var errs []error g.roots.Range(func(_ PipelineID, pipeline *registeredPipeline) bool { err := g.doReopen(ctx, pipeline.rootNode) if err != nil { - errors = multierror.Append(errors, err) + errs = append(errs, err) } return true }) - return errors.ErrorOrNil() + return errors.Join(errs...) } // Recursively reopen every node in the graph. @@ -163,17 +162,17 @@ func (g *graph) doReopen(ctx context.Context, node *linkedNode) error { } func (g *graph) validate() error { - var errors *multierror.Error + var errs []error g.roots.Range(func(_ PipelineID, pipeline *registeredPipeline) bool { err := g.doValidate(nil, pipeline.rootNode) if err != nil { - errors = multierror.Append(errors, err) + errs = append(errs, err) } return true }) - return errors.ErrorOrNil() + return errors.Join(errs...) } func (g *graph) doValidate(parent, node *linkedNode) error {