Skip to content

Commit 07084ef

Browse files
committed
Fix tests
1 parent 1ce4ce6 commit 07084ef

File tree

6 files changed

+17
-7
lines changed

6 files changed

+17
-7
lines changed

src/admin/__tests__/fetchTopicMetadata.spec.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ describe('Admin', () => {
101101
admin.fetchTopicMetadata({
102102
topics: [existingTopicName, newTopicName],
103103
})
104-
).rejects.toHaveProperty('message', 'This server does not host this topic-partition')
104+
).rejects.toHaveProperty(
105+
'message',
106+
`This server does not host this topic-partition [${newTopicName}]`
107+
)
105108
})
106109
})
107110
})

src/errors.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,14 @@ class KafkaJSOffsetOutOfRange extends KafkaJSProtocolError {
3838
}
3939
}
4040

41+
/**
42+
* Wraps 'UNKNOWN_TOPIC_OR_PARTITION' (code=3) but is only
43+
* used in cases where it is clearly the topic that is unknown
44+
* (e.g. a `metadata` request has no partition parameter)
45+
*/
4146
class KafkaJSUnknownTopic extends KafkaJSProtocolError {
4247
constructor(e, { topic }) {
43-
super(e)
48+
super(e, { retriable: false })
4449
this.topic = topic
4550
this.name = 'KafkaJSUnknownTopic'
4651
this.message = `${this.message} [${this.topic}]`
@@ -52,9 +57,10 @@ class KafkaJSTopicAuthorizationFailed extends KafkaJSProtocolError {
5257
super(e, { retriable: false })
5358
this.topic = topic
5459
this.name = 'KafkaJSTopicAuthorizationFailed'
55-
this.message = `${this.message} [${this.topic})]`
60+
this.message = `${this.message} [${this.topic}]`
5661
}
5762
}
63+
5864
class KafkaJSMemberIdRequired extends KafkaJSProtocolError {
5965
constructor(e, { memberId }) {
6066
super(e)

src/protocol/error.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const errorCodes = [
2424
{
2525
type: 'UNKNOWN_TOPIC_OR_PARTITION',
2626
code: 3,
27-
retriable: false,
27+
retriable: true,
2828
message: 'This server does not host this topic-partition',
2929
},
3030
{

src/protocol/requests/metadata/v0/response.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe('Protocol > Requests > Metadata > v0', () => {
7171
test('when topicErrorCode is UNKNOWN_TOPIC_OR_PARTITION', async () => {
7272
decoded.topicMetadata[0].topicErrorCode = 3
7373
await expect(response.parse(decoded)).rejects.toMatchObject({
74-
message: createErrorFromCode(3).message,
74+
message: createErrorFromCode(3).message + ' [test-topic-1]',
7575
retriable: false,
7676
type: 'UNKNOWN_TOPIC_OR_PARTITION',
7777
code: 3,
@@ -83,7 +83,7 @@ describe('Protocol > Requests > Metadata > v0', () => {
8383
test('when topicErrorCode is TOPIC_AUTHORIZATION_FAILED', async () => {
8484
decoded.topicMetadata[0].topicErrorCode = 29
8585
await expect(response.parse(decoded)).rejects.toMatchObject({
86-
message: createErrorFromCode(29).message,
86+
message: createErrorFromCode(29).message + ' [test-topic-1]',
8787
retriable: false,
8888
type: 'TOPIC_AUTHORIZATION_FAILED',
8989
code: 29,

types/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,7 @@ export interface KafkaJSOffsetOutOfRangeMetadata {
12901290
export interface KafkaJSUnknownTopicMetadata {
12911291
topic: string
12921292
}
1293+
12931294
export interface KafkaJSTopicAuthorizationFailedMetadata {
12941295
topic: string
12951296
}

types/tests.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,4 +342,4 @@ new KafkaJSServerDoesNotSupportApiKey(
342342
)
343343

344344
new KafkaJSUnknownTopic('This server does not host this topic-partition', { topic: 'my_topic' })
345-
new KafkaJSTopicAuthorizationFailed('Not authorized to access topics: [Topic authorization failed]', { topic: 'my_topic' })
345+
new KafkaJSTopicAuthorizationFailed('Not authorized to access topics: [Topic authorization failed]', { topic: 'my_topic' })

0 commit comments

Comments
 (0)