kafkajs icon indicating copy to clipboard operation
kafkajs copied to clipboard

[Bug Report] Issue with Space in Topic Name in kafkajs Library

Open zakhaev26 opened this issue 1 year ago • 1 comments

Describe the bug When attempting to create a topic using the kafkajs library, I encountered an issue related to topic names containing spaces. The library documentation specifies the use of the ITopicConfig structure for creating a topic, where the topic field is expected to be a string.

However, it seems that the library does not handle topic names with spaces correctly, leading to application errors.

To Reproduce

    
 //Attempt to create a topic using kafkajs with a name containing spaces, for example: "badminton score-updates".

const { Kafka } = require('kafkajs');

const kafka = new Kafka({
  clientId: 'my-app',
  brokers: ['localhost:9092']
});

const admin = kafka.admin();
admin.connect()
  .then(() => admin.createTopics({
    topics: [{
      topic: 'badminton score-updates',
      numPartitions: 2,
      replicationFactor: 1,
    }]
  }))
  .then(() => console.log('Topic created successfully!'))
  .catch(error => console.error('Error:', error))
  .finally(() => admin.disconnect());

Expected behavior The kafkajs library should provide clear guidance on valid topic name formats + Throw useful errors if done.

Observed behavior

{"level":"ERROR","timestamp":"2023-12-18T17:23:57.106Z","logger":"kafkajs","message":"[Connection] Response CreateTopics(key: 19, version: 3)","broker":"192.168.1.7:9092","clientId":"gc","error":"Topic creation errors","correlationId":2,"size":170}
KafkaJSAggregateError: Topic creation errors
    at Object.parse (/home/soubhik/codes/hypernotifs/kafka-files/node_modules/kafkajs/src/protocol/requests/createTopics/v0/response.js:29:11)
    at Connection.send (/home/soubhik/codes/hypernotifs/kafka-files/node_modules/kafkajs/src/network/connection.js:433:35)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async [private:Broker:sendRequest] (/home/soubhik/codes/hypernotifs/kafka-files/node_modules/kafkajs/src/broker/index.js:904:14)
    at async Broker.createTopics (/home/soubhik/codes/hypernotifs/kafka-files/node_modules/kafkajs/src/broker/index.js:555:12)
    at async /home/soubhik/codes/hypernotifs/kafka-files/node_modules/kafkajs/src/admin/index.js:171:9
    at async runAdmin (/home/soubhik/codes/hypernotifs/kafka-files/admin.js:12:9) {
  errors: [
    KafkaJSCreateTopicError: The request attempted to perform an operation on an invalid topic
        at /home/soubhik/codes/hypernotifs/kafka-files/node_modules/kafkajs/src/protocol/requests/createTopics/v0/response.js:32:18
        at Array.map (<anonymous>)
        at Object.parse (/home/soubhik/codes/hypernotifs/kafka-files/node_modules/kafkajs/src/protocol/requests/createTopics/v0/response.js:31:23)
        at Connection.send (/home/soubhik/codes/hypernotifs/kafka-files/node_modules/kafkajs/src/network/connection.js:433:35)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async [private:Broker:sendRequest] (/home/soubhik/codes/hypernotifs/kafka-files/node_modules/kafkajs/src/broker/index.js:904:14)
        at async Broker.createTopics (/home/soubhik/codes/hypernotifs/kafka-files/node_modules/kafkajs/src/broker/index.js:555:12)
        at async /home/soubhik/codes/hypernotifs/kafka-files/node_modules/kafkajs/src/admin/index.js:171:9
        at async runAdmin (/home/soubhik/codes/hypernotifs/kafka-files/admin.js:12:9) {
      retriable: false,
      helpUrl: undefined,
      type: 'INVALID_TOPIC_EXCEPTION',
      code: 17,
      topic: 'badminton score-updates',
      [cause]: undefined
    }
  ]
}

Environment:

  • OS: Linux thinkpad 6.2.0-37-generic 38~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov 2 18:01:13 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
  • KafkaJS version 2.2.4
  • Kafka version 7.4.0 [confluentinc/kafka docker image]
  • NodeJS version 20.10.0

zakhaev26 avatar Dec 18 '23 17:12 zakhaev26

I am up for taking up this issue.

zakhaev26 avatar Dec 18 '23 17:12 zakhaev26