diff --git a/bootstrap_test.go b/bootstrap_test.go index 2ed3ba4..9d4721b 100644 --- a/bootstrap_test.go +++ b/bootstrap_test.go @@ -5,7 +5,6 @@ import ( "errors" "testing" - "github.com/hashicorp/errwrap" "github.com/libp2p/go-libp2p/core/routing" ) @@ -152,7 +151,7 @@ func TestBootstrapErr(t *testing.T) { err := d.Bootstrap(ctx) t.Log(err) for _, s := range []string{"err1", "err2", "err3", "err4"} { - if !errwrap.Contains(err, s) { + if !errContains(err, s) { t.Errorf("expecting error to contain '%s'", s) } } diff --git a/composed.go b/composed.go index 7812bbd..de500a8 100644 --- a/composed.go +++ b/composed.go @@ -3,11 +3,11 @@ package routinghelpers import ( "context" - "github.com/hashicorp/go-multierror" "github.com/ipfs/go-cid" ci "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/routing" + "go.uber.org/multierr" ) // Compose composes the components into a single router. Not specifying a @@ -133,13 +133,13 @@ func (cr *Compose) Bootstrap(ctx context.Context) (err error) { } } - var me multierror.Error + var errs error for b := range routers { if err := b.Bootstrap(ctx); err != nil { - me.Errors = append(me.Errors, err) + errs = multierr.Append(errs, err) } } - return me.ErrorOrNil() + return errs } var _ routing.Routing = (*Compose)(nil) diff --git a/go.mod b/go.mod index 5369dae..09337f0 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,6 @@ go 1.23.0 require ( github.com/Jorropo/jsync v1.0.1 - github.com/hashicorp/errwrap v1.1.0 - github.com/hashicorp/go-multierror v1.1.1 github.com/ipfs/go-cid v0.5.0 github.com/ipfs/go-log/v2 v2.5.1 github.com/libp2p/go-libp2p v0.41.0 diff --git a/go.sum b/go.sum index 1328bf2..9b150cb 100644 --- a/go.sum +++ b/go.sum @@ -16,11 +16,6 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= 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/ipfs/go-block-format v0.2.0 h1:ZqrkxBA2ICbDRbK8KJs/u0O3dlp6gmAuuXUJNiW1Ycs= github.com/ipfs/go-block-format v0.2.0/go.mod h1:+jpL11nFx5A/SPpsoBn6Bzkra/zaArfSmsknbPMYgzM= github.com/ipfs/go-cid v0.5.0 h1:goEKKhaGm0ul11IHA7I6p1GmKz8kEYniqFopaB5Otwg= diff --git a/parallel.go b/parallel.go index d2cb4aa..fdc9139 100644 --- a/parallel.go +++ b/parallel.go @@ -8,12 +8,12 @@ import ( "sync" "github.com/Jorropo/jsync" - "github.com/hashicorp/go-multierror" "github.com/ipfs/go-cid" record "github.com/libp2p/go-libp2p-record" ci "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/routing" + "go.uber.org/multierr" ) // Parallel operates on the slice of routers in parallel. @@ -156,7 +156,7 @@ func (r Parallel) put(do func(routing.Routing) error) error { case 1: return errs[0] default: - return &multierror.Error{Errors: errs} + return multierr.Combine(errs...) } } @@ -273,7 +273,7 @@ func (r Parallel) get(ctx context.Context, do func(routing.Routing) (interface{} case 1: return nil, errs[0] default: - return nil, &multierror.Error{Errors: errs} + return nil, multierr.Combine(errs...) } } @@ -579,26 +579,26 @@ func fewProviders(ctx context.Context, out chan<- peer.AddrInfo, in []<-chan pee // Bootstrap signals all the sub-routers to bootstrap. func (r Parallel) Bootstrap(ctx context.Context) error { - var me multierror.Error + var errs error for _, b := range r.Routers { if err := b.Bootstrap(ctx); err != nil { - me.Errors = append(me.Errors, err) + errs = multierr.Append(errs, err) } } - return me.ErrorOrNil() + return errs } // Close closes all sub-routers that implement the io.Closer interface. func (r Parallel) Close() error { - var me multierror.Error + var errs error for _, router := range r.Routers { if closer, ok := router.(io.Closer); ok { if err := closer.Close(); err != nil { - me.Errors = append(me.Errors, err) + errs = multierr.Append(errs, err) } } } - return me.ErrorOrNil() + return errs } var _ routing.Routing = Parallel{} diff --git a/parallel_test.go b/parallel_test.go index 35333da..4fa2eda 100644 --- a/parallel_test.go +++ b/parallel_test.go @@ -3,14 +3,15 @@ package routinghelpers import ( "context" "errors" + "strings" "testing" "time" - "github.com/hashicorp/errwrap" "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/routing" mh "github.com/multiformats/go-multihash" + "go.uber.org/multierr" ) // NOTE: While this test is primarily testing the Parallel combinator, it also @@ -99,10 +100,10 @@ func TestParallelPutGet(t *testing.T) { if err := d.PutValue(ctx, "/notsupported/hello", []byte("world")); err != routing.ErrNotSupported { t.Fatalf("expected ErrNotSupported, got: %s", err) } - if err := d.PutValue(ctx, "/error/myErr", []byte("world")); !errwrap.Contains(err, "myErr") { + if err := d.PutValue(ctx, "/error/myErr", []byte("world")); !errContains(err, "myErr") { t.Fatalf("expected error to contain myErr, got: %s", err) } - if _, err := d.GetValue(ctx, "/error/myErr"); !errwrap.Contains(err, "myErr") { + if _, err := d.GetValue(ctx, "/error/myErr"); !errContains(err, "myErr") { t.Fatalf("expected error to contain myErr, got: %s", err) } if err := d.PutValue(ctx, "/solo/thing", []byte("value")); err != nil { @@ -129,6 +130,15 @@ func TestParallelPutGet(t *testing.T) { cancel() } +func errContains(err error, substr string) bool { + for _, e := range multierr.Errors(err) { + if strings.Contains(e.Error(), substr) { + return true + } + } + return false +} + func TestParallelPutFailure(t *testing.T) { ctx := context.Background() router := Parallel{ diff --git a/tiered.go b/tiered.go index 85313ca..188928b 100644 --- a/tiered.go +++ b/tiered.go @@ -4,12 +4,12 @@ import ( "context" "io" - "github.com/hashicorp/go-multierror" "github.com/ipfs/go-cid" record "github.com/libp2p/go-libp2p-record" ci "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/routing" + "go.uber.org/multierr" ) // Tiered is like the Parallel except that GetValue and FindPeer @@ -47,7 +47,7 @@ func (r Tiered) get(ctx context.Context, do func(routing.Routing) (interface{}, case 1: return nil, errs[0] default: - return nil, &multierror.Error{Errors: errs} + return nil, multierr.Combine(errs...) } } @@ -112,15 +112,15 @@ func (r Tiered) Bootstrap(ctx context.Context) error { // Close closes all sub-routers that implement the io.Closer interface. func (r Tiered) Close() error { - var me multierror.Error + var errs error for _, router := range r.Routers { if closer, ok := router.(io.Closer); ok { if err := closer.Close(); err != nil { - me.Errors = append(me.Errors, err) + errs = multierr.Append(errs, err) } } } - return me.ErrorOrNil() + return errs } var _ routing.Routing = Tiered{} diff --git a/tiered_test.go b/tiered_test.go index 305b18e..df01c63 100644 --- a/tiered_test.go +++ b/tiered_test.go @@ -5,7 +5,6 @@ import ( "context" "testing" - "github.com/hashicorp/errwrap" "github.com/ipfs/go-cid" record "github.com/libp2p/go-libp2p-record" "github.com/libp2p/go-libp2p/core/routing" @@ -178,11 +177,11 @@ func TestTieredGet(t *testing.T) { t.Fatal(err) } - if _, err := d.GetValue(ctx, "/error/myErr"); !errwrap.Contains(err, "myErr") { + if _, err := d.GetValue(ctx, "/error/myErr"); !errContains(err, "myErr") { t.Fatalf("expected error to contain myErr, got: %s", err) } - if _, err := (Tiered{Routers: []routing.Routing{d.Routers[1]}}).GetValue(ctx, "/error/myErr"); !errwrap.Contains(err, "myErr") { + if _, err := (Tiered{Routers: []routing.Routing{d.Routers[1]}}).GetValue(ctx, "/error/myErr"); !errContains(err, "myErr") { t.Fatalf("expected error to contain myErr, got: %s", err) }