snapshot of https://github.com/ThreeDotsLabs/watermill.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
master / ci (push) Failing after 0s
Some checks failed
master / ci (push) Failing after 0s
This commit is contained in:
39
internal/publisher/errors.go
Normal file
39
internal/publisher/errors.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package publisher
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/ThreeDotsLabs/watermill/message"
|
||||
)
|
||||
|
||||
type ErrCouldNotPublish struct {
|
||||
reasons map[string]error
|
||||
}
|
||||
|
||||
func (e *ErrCouldNotPublish) addMsg(msg *message.Message, reason error) {
|
||||
e.reasons[msg.UUID] = reason
|
||||
}
|
||||
|
||||
func NewErrCouldNotPublish() *ErrCouldNotPublish {
|
||||
return &ErrCouldNotPublish{make(map[string]error)}
|
||||
}
|
||||
|
||||
func (e ErrCouldNotPublish) Len() int {
|
||||
return len(e.reasons)
|
||||
}
|
||||
|
||||
func (e ErrCouldNotPublish) Error() string {
|
||||
if len(e.reasons) == 0 {
|
||||
return ""
|
||||
}
|
||||
b := strings.Builder{}
|
||||
b.WriteString("Could not publish the messages:\n")
|
||||
for uuid, reason := range e.reasons {
|
||||
b.WriteString(uuid + " : " + reason.Error() + "\n")
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func (e ErrCouldNotPublish) Reasons() map[string]error {
|
||||
return e.reasons
|
||||
}
|
||||
Reference in New Issue
Block a user