Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gfoltz committed Jan 7, 2024
1 parent 1ce4ce6 commit 07084ef
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/admin/__tests__/fetchTopicMetadata.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ describe('Admin', () => {
admin.fetchTopicMetadata({
topics: [existingTopicName, newTopicName],
})
).rejects.toHaveProperty('message', 'This server does not host this topic-partition')
).rejects.toHaveProperty(
'message',
`This server does not host this topic-partition [${newTopicName}]`
)
})
})
})
10 changes: 8 additions & 2 deletions src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ class KafkaJSOffsetOutOfRange extends KafkaJSProtocolError {
}
}

/**
* Wraps 'UNKNOWN_TOPIC_OR_PARTITION' (code=3) but is only
* used in cases where it is clearly the topic that is unknown
* (e.g. a `metadata` request has no partition parameter)
*/
class KafkaJSUnknownTopic extends KafkaJSProtocolError {
constructor(e, { topic }) {
super(e)
super(e, { retriable: false })
this.topic = topic
this.name = 'KafkaJSUnknownTopic'
this.message = `${this.message} [${this.topic}]`
Expand All @@ -52,9 +57,10 @@ class KafkaJSTopicAuthorizationFailed extends KafkaJSProtocolError {
super(e, { retriable: false })
this.topic = topic
this.name = 'KafkaJSTopicAuthorizationFailed'
this.message = `${this.message} [${this.topic})]`
this.message = `${this.message} [${this.topic}]`
}
}

class KafkaJSMemberIdRequired extends KafkaJSProtocolError {
constructor(e, { memberId }) {
super(e)
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const errorCodes = [
{
type: 'UNKNOWN_TOPIC_OR_PARTITION',
code: 3,
retriable: false,
retriable: true,
message: 'This server does not host this topic-partition',
},
{
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/requests/metadata/v0/response.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('Protocol > Requests > Metadata > v0', () => {
test('when topicErrorCode is UNKNOWN_TOPIC_OR_PARTITION', async () => {
decoded.topicMetadata[0].topicErrorCode = 3
await expect(response.parse(decoded)).rejects.toMatchObject({
message: createErrorFromCode(3).message,
message: createErrorFromCode(3).message + ' [test-topic-1]',
retriable: false,
type: 'UNKNOWN_TOPIC_OR_PARTITION',
code: 3,
Expand All @@ -83,7 +83,7 @@ describe('Protocol > Requests > Metadata > v0', () => {
test('when topicErrorCode is TOPIC_AUTHORIZATION_FAILED', async () => {
decoded.topicMetadata[0].topicErrorCode = 29
await expect(response.parse(decoded)).rejects.toMatchObject({
message: createErrorFromCode(29).message,
message: createErrorFromCode(29).message + ' [test-topic-1]',
retriable: false,
type: 'TOPIC_AUTHORIZATION_FAILED',
code: 29,
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,7 @@ export interface KafkaJSOffsetOutOfRangeMetadata {
export interface KafkaJSUnknownTopicMetadata {
topic: string
}

export interface KafkaJSTopicAuthorizationFailedMetadata {
topic: string
}
Expand Down
2 changes: 1 addition & 1 deletion types/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,4 @@ new KafkaJSServerDoesNotSupportApiKey(
)

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

0 comments on commit 07084ef

Please sign in to comment.