diff --git a/aws/sqs/sqs.go b/aws/sqs/sqs.go index 404fe93..819cca0 100644 --- a/aws/sqs/sqs.go +++ b/aws/sqs/sqs.go @@ -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. @@ -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] @@ -333,3 +337,7 @@ func Cancelled(err error) bool { } return false } + +func IsNoMessagesError(err error) bool { + return errors.Is(err, ErrNoMessages) +}