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

Conversation

fishi0x01
Copy link
Contributor

When sqs consumer fails it would be nice to see the messages it failed on. Usually this stems from some formatting issue which is much easier to spot if we see the message sample in the logs.

Comment on lines +61 to +70
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
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants