Skip to content

Improving error subscription log#427

Merged
CarlosGamero merged 2 commits intomainfrom
feat/improve_subscription_error_log
Apr 20, 2026
Merged

Improving error subscription log#427
CarlosGamero merged 2 commits intomainfrom
feat/improve_subscription_error_log

Conversation

@CarlosGamero
Copy link
Copy Markdown
Collaborator

@CarlosGamero CarlosGamero commented Apr 20, 2026

Summary by CodeRabbit

  • New Features

    • Added support for updating subscriptions that already exist with different attributes.
  • Bug Fixes

    • Improved error handling and logging for subscription operations to provide more conditional and informative error messages.

@CarlosGamero CarlosGamero self-assigned this Apr 20, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 20, 2026

Warning

Rate limit exceeded

@CarlosGamero has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 49 minutes and 26 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 49 minutes and 26 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0f03d047-6463-4517-82eb-e0240660bf27

📥 Commits

Reviewing files that changed from the base of the PR and between a1a97ea and 84b76d4.

📒 Files selected for processing (1)
  • packages/sns/test/utils/testSnsConfig.ts
📝 Walkthrough

Walkthrough

The error handling logic in the SNS subscriber's subscribeToTopic function is adjusted to conditionally log errors. Instead of always logging errors immediately, logging is now deferred until after checking if an update operation should be attempted when a subscription already exists with different attributes.

Changes

Cohort / File(s) Summary
Error Handling Refinement
packages/sns/lib/utils/snsSubscriber.ts
Conditional error logging in subscribeToTopic: removed unconditional initial error log; logging now occurs only if update is not attempted or if update fails. When updateAttributesIfExists is enabled and error indicates existing subscription with different attributes, a warning is logged before attempting update; otherwise, error is logged before throwing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 When subscriptions clash and attributes fray,
We log with wisdom, not haste, I say!
Conditional checks before we cry—
Update if we can, or error nearby.
Smart handling makes the morning bright! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: improving error logging in subscription handling by making it conditional and more informative.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/improve_subscription_error_log

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/sns/lib/utils/snsSubscriber.ts`:
- Around line 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.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3ee2363d-69d5-440c-b672-162c69e27403

📥 Commits

Reviewing files that changed from the base of the PR and between e32e559 and a1a97ea.

📒 Files selected for processing (1)
  • packages/sns/lib/utils/snsSubscriber.ts

Comment on lines 118 to +120
logger.error('Failed to update subscription')
} else {
logger.error(errMessage)
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

@CarlosGamero CarlosGamero merged commit b17e658 into main Apr 20, 2026
9 checks passed
@CarlosGamero CarlosGamero deleted the feat/improve_subscription_error_log branch April 20, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants