[fix] pass string as first arg to user logger on error events#483
Open
Emanuele Sabellico (emasab) wants to merge 2 commits into
Open
[fix] pass string as first arg to user logger on error events#483Emanuele Sabellico (emasab) wants to merge 2 commits into
Emanuele Sabellico (emasab) wants to merge 2 commits into
Conversation
The producer/consumer #errorCb forwarded the raw Error object as the
first arg to the user-supplied logger, while admin used a string. Make
all three pass `Error: ${err.message}`. Also always log on error (not
only after CONNECTED) and default `name` in binding metadata to '' when
the client name is not yet available. Add unit test covering all three.
There was a problem hiding this comment.
Pull request overview
Standardizes KafkaJS-compatible client error logging so user-supplied loggers consistently receive a string message (instead of sometimes an Error object), and ensures error events are logged even before the client reaches CONNECTED. It also makes binding log metadata more robust when the client name is not yet known.
Changes:
- Producer/Consumer/Admin error callbacks now call
logger.errorwithError: ${err.message}as the first argument. - Consumer/Admin now log on error regardless of connection state (while still capturing connection errors for connect rejection).
- Binding log metadata now defaults
nameto''when the client name is unavailable, and a Jest unit test is added to cover the three client types.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/promisified/unit/logger.spec.js | Adds unit tests asserting user logger receives a string first argument on error callbacks. |
| lib/kafkajs/_producer.js | Updates producer error logging to pass a formatted string message. |
| lib/kafkajs/_consumer.js | Updates consumer error logging to always log and to pass a formatted string message. |
| lib/kafkajs/_admin.js | Updates admin error logging to always log and to pass a formatted string message. |
| lib/kafkajs/_common.js | Defaults binding metadata name to '' when client name is not available. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The producer/consumer #errorCb forwarded the raw Error object as the first arg to the user-supplied logger, while admin used a string. Make all three pass
Error: ${err.message}. Also always log on error (not only after CONNECTED) and defaultnamein binding metadata to '' when the client name is not yet available. Add unit test covering all three.