Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print sqs messages on error #4621

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions reconcile/utils/sqs_gateway.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
import os

from reconcile.utils.aws_api import AWSApi
Expand Down Expand Up @@ -57,12 +58,16 @@ def receive_messages(
visibility_timeout=30,
wait_time_seconds=20,
):
messages = self.sqs.receive_message(
QueueUrl=self.queue_url,
VisibilityTimeout=visibility_timeout,
WaitTimeSeconds=wait_time_seconds,
).get("Messages", [])
return [(m["ReceiptHandle"], json.loads(m["Body"])) for m in messages]
try:
messages = self.sqs.receive_message(
QueueUrl=self.queue_url,
VisibilityTimeout=visibility_timeout,
WaitTimeSeconds=wait_time_seconds,
).get("Messages", [])
return [(m["ReceiptHandle"], json.loads(m["Body"])) for m in messages]
except Exception as e:
logging.error(f"Error receiving messages from SQS: {messages=}")
raise e
Comment on lines +61 to +70
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When there is exception raised in receive_message, messages will be undefined, try to access it will raise another NameError.

If we just want to capture json.loads exceptions, should only put that in try block, and just raise to keep stack.


def delete_message(self, receipt_handle):
self.sqs.delete_message(QueueUrl=self.queue_url, ReceiptHandle=receipt_handle)