Skip to content

Commit b9bac80

Browse files
jpradassgo-master
andauthored
made Unmarshaller more resiliant and added clearer error if uuid header is missing (#40)
Co-authored-by: go-master <josue.pradas.tech@bbva.com>
1 parent b24164b commit b9bac80

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

pkg/redisstream/marshaller.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,17 @@ func (DefaultMarshallerUnmarshaller) Marshal(_ string, msg *message.Message) (ma
4646
}
4747

4848
func (DefaultMarshallerUnmarshaller) Unmarshal(values map[string]interface{}) (msg *message.Message, err error) {
49-
msg = message.NewMessage(values[UUIDHeaderKey].(string), []byte(values["payload"].(string)))
49+
var uuid, payload any
50+
uuid, payload = values[UUIDHeaderKey], values["payload"]
51+
if uuid == nil {
52+
return nil, errors.Errorf("%s key is missing as part of the message", UUIDHeaderKey)
53+
}
54+
55+
if payload == nil {
56+
payload = ""
57+
}
58+
59+
msg = message.NewMessage(uuid.(string), []byte(payload.(string)))
5060

5161
md := values["metadata"]
5262
if md != nil {

0 commit comments

Comments
 (0)