Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion packages/sns/lib/utils/snsSubscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ export async function subscribeToTopic(
? topicConfiguration.Name
: topicConfiguration.topicName
}": ${err.message}`
logger.error(errMessage)

if (
subscriptionConfiguration.updateAttributesIfExists &&
err.message.indexOf('Subscription already exists with different attributes') !== -1
) {
logger.warn(`${errMessage}. Trying to update subscription`)

const result = await tryToUpdateSubscription(
snsClient,
topicArn,
Expand All @@ -115,6 +116,8 @@ export async function subscribeToTopic(
}

logger.error('Failed to update subscription')
} else {
logger.error(errMessage)
Comment on lines 118 to +120
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot Apr 20, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Preserve the subscription context in the update-failure error log.

When the update path fails, the only error-level log is the generic "Failed to update subscription", so logs lose the queue/topic and original SNS error details from errMessage. Keep the contextual message here too.

🪵 Proposed logging fix
-      logger.error('Failed to update subscription')
+      logger.error(`${errMessage}. Failed to update subscription`)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
logger.error('Failed to update subscription')
} else {
logger.error(errMessage)
logger.error(`${errMessage}. Failed to update subscription`)
} else {
logger.error(errMessage)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/sns/lib/utils/snsSubscriber.ts` around lines 118 - 120, The error
log in the update-failure branch currently only calls logger.error('Failed to
update subscription') which loses context and the original SNS error; change
that else branch to log the failure message together with errMessage and the
subscription context (e.g., topic ARN / queue name or the subscription object
available in this scope) using the existing logger (replace the bare message
with something like logger.error('Failed to update subscription', {
subscription: <subscriptionContext>, err: errMessage }) or a formatted string)
so the log retains topic/queue and original SNS error details; update the else
branch where logger.error(errMessage) is used to include both the descriptive
message and the contextual fields.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

this looks important

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@kibertoad, agreed! Without the fix, when the update path fails, the log entry "Failed to update subscription" provides no actionable context — operators won't know which queue or topic was affected, or what the original SNS error was.

The one-line fix pulls the already-constructed errMessage (which includes queue name, topic name, and the original error) into the failure log:

-      logger.error('Failed to update subscription')
+      logger.error(`${errMessage}. Failed to update subscription`)

This ensures the log entry for the update-failure case is as informative as the one in the else branch added in this PR.

Copy link
Copy Markdown
Collaborator Author

@CarlosGamero CarlosGamero Apr 20, 2026

Choose a reason for hiding this comment

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

@kibertoad In this flow we will have:

warn -> Error while creating subscription for queue "XXX", topic "YYYY": ${errMessage}. Trying to update subscription
error -> Failed to update subscription

I feel it is meaningful enough and adding errMessage again in the error can make it confusing, what do you think?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

sure, that is reasonable

}

throw new InternalError({
Expand Down
4 changes: 2 additions & 2 deletions packages/sns/test/utils/testSnsConfig.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { S3ClientConfig } from '@aws-sdk/client-s3'
import type { SNSClientConfig } from '@aws-sdk/client-sns'
import type { SQSClientConfig } from '@aws-sdk/client-sqs'
import type { STSClientConfig } from '@aws-sdk/client-sts'
import { createLocalhostHandler } from 'fauxqs'

import { getPort } from './fauxqsInstance.ts'

const isLocalstack = process.env.QUEUE_BACKEND === 'localstack'
const port = getPort()

export const TEST_AWS_CONFIG: SNSClientConfig & SQSClientConfig = {
export const TEST_AWS_CONFIG: SNSClientConfig & SQSClientConfig & STSClientConfig = {
endpoint: `http://localhost:${port}`,
region: 'eu-west-1',
credentials: {
Expand Down
Loading