Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default logger fails to log BigInt #1233

Closed
Nevon opened this issue Nov 22, 2021 · 0 comments · Fixed by #1234
Closed

Default logger fails to log BigInt #1233

Nevon opened this issue Nov 22, 2021 · 0 comments · Fixed by #1234
Labels

Comments

@Nevon
Copy link
Collaborator

Nevon commented Nov 22, 2021

Describe the bug
When enabling debug logging to investigate an unrelated issue, we started seeing TypeErrors from the logger.

This appears to be because offsets are BigInts and JSON.stringify doesn't know how to serialize those:

> const val = { foo: 100n }
undefined
> JSON.stringify(val)
Uncaught TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)

To Reproduce

Enable debug logging and run consumer.commitOffsets without first having run consumer.run. The debug message contains offsets which are BigInts.

Expected behavior
The log should serialize the bigints to strings.

Observed behavior

TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)
    at /home/klarna/app/node_modules/kafkajs/src/loggers/console.js:5:24
    at Object.debug (/home/klarna/app/node_modules/kafkajs/src/loggers/index.js:16:3)
    at Runner.commitOffsets (/home/klarna/app/node_modules/kafkajs/src/consumer/runner.js:467:19)
    at Object.commitOffsets (/home/klarna/app/node_modules/kafkajs/src/consumer/index.js:369:19)
    at KafkaJsClient.commit (/home/klarna/app/pubsub/kafkajs/index.js:115:14)
    at /home/klarna/app/consumer/index.js:314:101
    at Runner.eachMessage (/home/klarna/app/pubsub/kafkajs/index.js:55:21)
    at Runner.processEachMessage (/home/klarna/app/node_modules/kafkajs/src/consumer/runner.js:151:20)
    at onBatch (/home/klarna/app/node_modules/kafkajs/src/consumer/runner.js:287:20)

Environment:

  • OS: Amazon Linux 2
  • KafkaJS version: 1.15.0
  • NodeJS version 12-something, but can reproduce in 14 and 16 as well
@Nevon Nevon added the bug label Nov 22, 2021
Nevon added a commit that referenced this issue Nov 22, 2021
Nevon added a commit that referenced this issue Nov 22, 2021
Nevon added a commit that referenced this issue Nov 22, 2021
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 a pull request may close this issue.

1 participant