From 38a040e213cc8af5b01b3afe422481493f54382f Mon Sep 17 00:00:00 2001 From: Alex Hong <9397363+hongalex@users.noreply.github.com> Date: Mon, 28 Aug 2023 14:07:41 -0700 Subject: [PATCH] fix(pubsub): make AckWithResult return success when constructed (#8489) --- internal/pubsub/message.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/pubsub/message.go b/internal/pubsub/message.go index 7d7092b19100..5dc25666a072 100644 --- a/internal/pubsub/message.go +++ b/internal/pubsub/message.go @@ -186,7 +186,9 @@ func (m *Message) AckWithResult() *AckResult { if m.ackh != nil { return m.ackh.OnAckWithResult() } - return nil + // When the message was constructed directly rather passed in the callback in `sub.Receive`, + // ready the message with success so calling `AckResult.Get` doesn't panic. + return newSuccessAckResult() } // NackWithResult declines to acknowledge the message which indicates that @@ -206,7 +208,9 @@ func (m *Message) NackWithResult() *AckResult { if m.ackh != nil { return m.ackh.OnNackWithResult() } - return nil + // When the message was constructed directly rather passed in the callback in `sub.Receive`, + // ready the message with success so calling `AckResult.Get` doesn't panic. + return newSuccessAckResult() } // NewMessage creates a message with an AckHandler implementation, which should @@ -219,3 +223,9 @@ func NewMessage(ackh AckHandler) *Message { func MessageAckHandler(m *Message) AckHandler { return m.ackh } + +func newSuccessAckResult() *AckResult { + ar := NewAckResult() + SetAckResult(ar, AcknowledgeStatusSuccess, nil) + return ar +}