Skip to content

Commit

Permalink
update SQS receiveMessage to return no messages error when no message…
Browse files Browse the repository at this point in the history
…s received from the quque
  • Loading branch information
bpeng committed Nov 11, 2024
1 parent 7d93e76 commit 4190da6
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion aws/sqs/sqs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type SQS struct {
client *sqs.Client
}

// specific error to return when no messages are received from the queue
var ErrNoMessages = errors.New("no messages received from queue")

// New returns an SQS struct which wraps an SQS client using the default AWS credentials chain.
// This consults (in order) environment vars, config files, EC2 and ECS roles.
// It is an error if the AWS_REGION environment variable is not set.
Expand Down Expand Up @@ -135,7 +138,8 @@ func (s *SQS) receiveMessage(ctx context.Context, input *sqs.ReceiveMessageInput
switch {
case r == nil || len(r.Messages) == 0:
// no message received
continue
return Raw{}, ErrNoMessages

case len(r.Messages) == 1:
raw := r.Messages[0]

Expand Down Expand Up @@ -333,3 +337,7 @@ func Cancelled(err error) bool {
}
return false
}

func IsNoMessagesError(err error) bool {
return errors.Is(err, ErrNoMessages)
}

0 comments on commit 4190da6

Please sign in to comment.