Skip to content

Conversation

@kibertoad
Copy link
Owner

@kibertoad kibertoad commented Nov 21, 2025

Class methods lose reference to this when passed outside of an instance

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling to ensure proper context preservation during initialization, resulting in more reliable error processing in edge cases.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Nov 21, 2025

Walkthrough

Fixed error handling in the non-batch initialization path of AbstractKafkaConsumer. Replaced direct method reference with an arrow function wrapper in the promise rejection handler to properly preserve the this context when invoking the error handler.

Changes

Cohort / File(s) Summary
Error Handler Context Fix
packages/kafka/lib/AbstractKafkaConsumer.ts
Changed error handling from .catch(this.handlerError) to .catch((error) => this.handlerError(error)) to preserve proper this binding in non-batch init path

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Key focus area: Verify that the arrow function wrapper correctly preserves this context and that the handler receives the error parameter as expected.
  • Pattern validation: Confirm this matches the error handling pattern used elsewhere in the codebase for consistency.

Poem

🐰 A binding fix, small but true,
Arrow functions preserve this for you,
Error handlers now work as they should,
This context flows just like it would. ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix passing instance method as param' accurately describes the main change: fixing error handling by using an arrow function to preserve the 'this' context instead of passing the method directly.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/logging

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 39234ae and 38893c7.

📒 Files selected for processing (1)
  • packages/kafka/lib/AbstractKafkaConsumer.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: general (24.x, @message-queue-toolkit/redis-message-deduplication-store) / build
  • GitHub Check: general (22.x, @message-queue-toolkit/sqs) / build
  • GitHub Check: general (22.x, @message-queue-toolkit/sns) / build
  • GitHub Check: general (22.x, @message-queue-toolkit/redis-message-deduplication-store) / build
  • GitHub Check: general (22.x, @message-queue-toolkit/s3-payload-store) / build
  • GitHub Check: general (20.x, @message-queue-toolkit/amqp) / build
  • GitHub Check: general (20.x, @message-queue-toolkit/redis-message-deduplication-store) / build
  • GitHub Check: general (20.x, @message-queue-toolkit/s3-payload-store) / build
  • GitHub Check: general (20.x, @message-queue-toolkit/sqs) / build
  • GitHub Check: general (24.x, @message-queue-toolkit/sqs) / build
  • GitHub Check: general (20.x, @message-queue-toolkit/sns) / build
  • GitHub Check: general (24.x, @message-queue-toolkit/sns) / build
  • GitHub Check: kafka (24.x) / build
  • GitHub Check: kafka (22.x) / build
🔇 Additional comments (1)
packages/kafka/lib/AbstractKafkaConsumer.ts (1)

219-219: LGTM! Critical fix for this context binding.

This change correctly preserves the this context when passing the error handler to .catch(). Without the arrow function wrapper, the method reference would lose its binding, causing runtime errors. The fix is now consistent with the error handlers on lines 212 and 222.


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.

@kibertoad kibertoad merged commit 220e461 into main Nov 21, 2025
31 checks passed
@kibertoad kibertoad deleted the fix/logging branch November 21, 2025 18:59
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