From 085f06ae46a2ca60c1999d1ad1d06a09b794b325 Mon Sep 17 00:00:00 2001 From: Alex Hong <9397363+hongalex@users.noreply.github.com> Date: Thu, 24 Aug 2023 18:49:23 -0700 Subject: [PATCH] fix(pubsub): make AckWithResult return success when constructed --- 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 +}