bbc / sqs-consumer

Build Amazon Simple Queue Service (SQS) based applications without the boilerplate
https://bbc.github.io/sqs-consumer/
Other
1.74k stars 333 forks source link

[Feature Request]: Enhance SQSError with AWS error $response object for Better Debugging #495

Closed nirf closed 4 months ago

nirf commented 4 months ago

Describe the bug

Description: Currently, when an error occurs in the deleteMessage method of the sqs-consumer npm library, the thrown error from AWS includes a $response object which is crucial for debugging. However, this $response object is not accessible through the SQSError, which makes it challenging to understand the underlying issue, especially in cases of deserialization errors.

Error message example: "SQS delete message failed: Unexpected token < in JSON at position 0\n Deserialization error: to see the raw response, inspect the hidden field {error}.$response on this object."

For instance, if the SQS deleteMessage operation fails due to an unexpected token in the JSON (e.g., "Unexpected token < in JSON at position 0"), the raw response from AWS could provide critical insights into what went wrong. Unfortunately, without access to the $response object, developers are left guessing, potentially leading to increased debugging time and slower resolution.

Proposal: Extend the SQSError class to include the $response object from AWS errors. This enhancement would allow developers to inspect the raw AWS response directly from the SQSError instance, facilitating quicker and more effective troubleshooting.

Impact: Incorporating the $response object into SQSError would significantly improve the developer experience by providing more detailed error contexts directly, aiding in faster bug resolutions and reducing downtime in production environments.

Thanks

Your minimal, reproducible example

https://gist.github.com/nirf/f2ac58f2a6a837d4f3a55d491a395dab

Steps to reproduce

update the toSQSError function

Expected behavior

access to the aws error $response object for better debugging

How often does this bug happen?

Often

Screenshots or Videos

No response

Platform

Node version - 18.12.1

Package version

7.5.0

AWS SDK version

3.428.0

Additional context

Great Library :-)

nicholasgriffintn commented 4 months ago

Hey, thanks for raising this issue!

This makes a lot of sense, not sure why we don't already really.

nicholasgriffintn commented 4 months ago

I've popped an initial mock up here: https://github.com/bbc/sqs-consumer/pull/496

This keeps the error object the same as it is today by default but adds a new option that will extend the output with both response and metadata, so best of both worlds.

github-actions[bot] commented 4 months ago

:tada: This issue has been resolved in version 10.3.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

nirf commented 4 months ago

Thanks 👍

github-actions[bot] commented 3 months ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.