Skip to content

Commit

Permalink
Use github.com/hashicorp/go-multierror instead creating it (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbret89 authored Jul 18, 2024
1 parent c634bd9 commit 9c37c10
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 49 deletions.
11 changes: 4 additions & 7 deletions provider/memory/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"sync"

"github.com/botchris/go-pubsub"
"github.com/hashicorp/go-multierror"
"github.com/kubemq-io/kubemq-go/pkg/uuid"
)

Expand Down Expand Up @@ -39,23 +40,19 @@ func (b *broker) Publish(ctx context.Context, topic pubsub.Topic, m interface{})
t := b.openTopic(topic)
b.Unlock()

multiErrs := mewMultiErrs()
errors := &multierror.Error{}

for _, result := range t.publish(ctx, m) {
if result.err != nil && !b.withPublishErrors {
continue
}

if result.err != nil && b.withPublishErrors {
multiErrs.add(result.err)
errors = multierror.Append(errors, result.err)
}
}

if !multiErrs.isEmpty() {
return multiErrs
}

return nil
return errors.ErrorOrNil()
}

func (b *broker) Subscribe(_ context.Context, topic pubsub.Topic, handler pubsub.Handler, option ...pubsub.SubscribeOption) (pubsub.Subscription, error) {
Expand Down
4 changes: 2 additions & 2 deletions provider/memory/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ func Test_Broker_Publish(t *testing.T) {
t.Run("THEN it returns both errors", func(t *testing.T) {
require.Error(t, publishErr)

assert.Contains(t, publishErr.Error(), assert.AnError.Error())
assert.Contains(t, publishErr.Error(), otherErr.Error())
assert.ErrorIs(t, publishErr, assert.AnError)
assert.ErrorIs(t, publishErr, otherErr)
})
})
})
Expand Down
40 changes: 0 additions & 40 deletions provider/memory/error.go

This file was deleted.

0 comments on commit 9c37c10

Please sign in to comment.