Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/admin/__tests__/deleteTopics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ describe('Admin', () => {
await expect(admin.deleteTopics({ topics: [topicName] })).resolves.toBe()
})

test('failt to delete not existing topic', async () => {
admin = createAdmin({ cluster: createCluster(), logger: newLogger() })

await admin.connect()
await expect(admin.deleteTopics({ topics: [topicName] })).rejects.toHaveProperty(
'message',
'Delete topics error'
)
})

test('remove deleted topics from the cluster target group', async () => {
const cluster = createCluster()
admin = createAdmin({ cluster, logger: newLogger() })
Expand Down
21 changes: 19 additions & 2 deletions src/admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,25 @@ module.exports = ({

await cluster.refreshMetadata()
} catch (e) {
if (['NOT_CONTROLLER', 'UNKNOWN_TOPIC_OR_PARTITION'].includes(e.type)) {
logger.warn('Could not delete topics', { error: e.message, retryCount, retryTime })
if (
e.name === 'KafkaJSAggregateError' &&
e.errors.some(error => error.type.includes('UNKNOWN_TOPIC_OR_PARTITION'))
Copy link

Choose a reason for hiding this comment

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

This should be error => error.type === 'UNKNOWN_TOPIC_OR_PARTITION'. The use of includes in the original code was on an Array. But here you're using it on a string, which works but I think only accidentally, and I'm pretty sure is not what you intend.

Copy link
Author

Choose a reason for hiding this comment

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

This one is also changed.

Thank you.

) {
logger.warn('Could not delete topics', {
error: e.message,
retryCount,
retryTime,
topics: e.errors.map(error => error.topic),
})
throw e
}

if ('NOT_CONTROLLER'.includes(e.type)) {
Copy link

Choose a reason for hiding this comment

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

Same here, this should be e.type === 'NOT_CONTROLLER'.

Copy link
Author

Choose a reason for hiding this comment

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

@gfoltz you are totally right. I have changed how error type is checked.

Thank you.

logger.warn('Could not delete topics', {
error: e.message,
retryCount,
retryTime,
})
throw e
}

Expand Down
9 changes: 9 additions & 0 deletions src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ class KafkaJSCreateTopicError extends KafkaJSProtocolError {
}
}

class KafkaJSDeleteTopicError extends KafkaJSProtocolError {
constructor(e, topicName) {
super(e)
this.topic = topicName
this.name = 'KafkaJSDeleteTopicError'
}
}

class KafkaJSAlterPartitionReassignmentsError extends KafkaJSProtocolError {
constructor(e, topicName, partition) {
super(e)
Expand Down Expand Up @@ -304,6 +312,7 @@ module.exports = {
KafkaJSFetcherRebalanceError,
KafkaJSNoBrokerAvailableError,
KafkaJSAlterPartitionReassignmentsError,
KafkaJSDeleteTopicError,
isRebalancing,
isKafkaJSError,
}
8 changes: 7 additions & 1 deletion src/protocol/requests/deleteTopics/v0/response.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Decoder = require('../../../decoder')
const { failure, createErrorFromCode } = require('../../../error')
const { KafkaJSDeleteTopicError, KafkaJSAggregateError } = require('../../../../errors')

/**
* DeleteTopics Response (Version: 0) => [topic_error_codes]
Expand All @@ -25,7 +26,12 @@ const decode = async rawData => {
const parse = async data => {
const topicsWithError = data.topicErrors.filter(({ errorCode }) => failure(errorCode))
if (topicsWithError.length > 0) {
throw createErrorFromCode(topicsWithError[0].errorCode)
throw new KafkaJSAggregateError(
'Delete topics error',
topicsWithError.map(
error => new KafkaJSDeleteTopicError(createErrorFromCode(error.errorCode), error.topic)
)
)
}

return data
Expand Down