diff --git a/compparallel.go b/compparallel.go index 4c12188..bbfd770 100644 --- a/compparallel.go +++ b/compparallel.go @@ -231,9 +231,14 @@ func getValueOrErrorParallel[T any]( ctx, cancel := withCancelAndOptionalTimeout(ctx, r.Timeout) defer cancel() value, empty, err := f(ctx, r.Router) - if err != nil && - !errors.Is(err, routing.ErrNotFound) && - !r.IgnoreError { + if err != nil { + if r.IgnoreError || errors.Is(err, routing.ErrNotFound) { + log.Debug("getValueOrErrorParallel: not found or ignorable error for router ", r.Router, + " with timeout ", r.Timeout, + " and ignore errors ", r.IgnoreError, + ) + return + } log.Debug("getValueOrErrorParallel: error calling router function for router ", r.Router, " with timeout ", r.Timeout, " and ignore errors ", r.IgnoreError, diff --git a/compparallel_test.go b/compparallel_test.go index a5d7b63..63e0512 100644 --- a/compparallel_test.go +++ b/compparallel_test.go @@ -308,6 +308,28 @@ func TestComposableParallelFixtures(t *testing.T) { {key: "/wait/100ms/a", value: "av", searchValCount: 1}, }, }, + { + Name: "Return an error even if routers return data alongside the error", + routers: []*ParallelRouter{ + { + Timeout: 0, + IgnoreError: true, + Router: &Compose{ + PeerRouting: peerRoutingDataWithError{}, + }, + }, + { + Timeout: time.Second, + IgnoreError: true, + Router: &Compose{ + PeerRouting: peerRoutingDataWithError{}, + }, + }, + }, + FindPeer: []findPeerFixture{ + {peerID: "pid1", err: routing.ErrNotFound}, + }, + }, } for _, f := range fixtures { @@ -402,6 +424,12 @@ func TestComposableParallelFixtures(t *testing.T) { } } +type peerRoutingDataWithError struct{} + +func (r peerRoutingDataWithError) FindPeer(ctx context.Context, p peer.ID) (peer.AddrInfo, error) { + return peer.AddrInfo{ID: p}, routing.ErrNotFound +} + func newDummyPeerRouting(t testing.TB, ids []peer.ID) routing.PeerRouting { pr := dummyPeerRouter{} for _, id := range ids { diff --git a/version.json b/version.json index e618866..257cf0b 100644 --- a/version.json +++ b/version.json @@ -1,3 +1,3 @@ { - "version": "v0.7.2" + "version": "v0.7.3" }