Skip to content

[fix] pass string as first arg to user logger on error events#483

Open
Emanuele Sabellico (emasab) wants to merge 2 commits into
masterfrom
dev/fix-passing-object-to-logger
Open

[fix] pass string as first arg to user logger on error events#483
Emanuele Sabellico (emasab) wants to merge 2 commits into
masterfrom
dev/fix-passing-object-to-logger

Conversation

@emasab
Copy link
Copy Markdown
Contributor

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.

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.
@emasab Emanuele Sabellico (emasab) requested a review from a team as a code owner May 8, 2026 13:57
Copilot AI review requested due to automatic review settings May 8, 2026 13:57
@emasab Emanuele Sabellico (emasab) requested a review from a team as a code owner May 8, 2026 13:57
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.error with Error: ${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 name to '' 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.

Comment thread test/promisified/unit/logger.spec.js Outdated
Comment thread test/promisified/unit/logger.spec.js Outdated
Comment thread test/promisified/unit/logger.spec.js Outdated
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