Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/network/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export class Connection extends EventEmitter {
} catch (err) {
diagnostic.error = err as Error
connectionsApiChannel.error.publish(diagnostic)
throw err
return callback(err, undefined as unknown as ReturnType)
}

writer.appendFrom(payload).prependLength()
Expand Down
26 changes: 26 additions & 0 deletions test/clients/producer/producer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import * as Prometheus from 'prom-client'
import { kConnections } from '../../../src/clients/base/base.ts'
import {
type ClientDiagnosticEvent,
compressionsAlgorithms,
GenericError,
initProducerIdV5,
instancesChannel,
MultipleErrors,
Expand Down Expand Up @@ -691,6 +693,30 @@ test('send should auto-initialize idempotent producer if needed', async t => {
strictEqual(result.offsets?.length, 1)
})

test('send should handle synchronuous error during payload creation', async t => {
const producer = createProducer(t, { strict: true })
const testTopic = await createTopic(t)

const compression = 'lz4'
const expectedError = new GenericError('PLT_KFK_UNSUPPORTED_COMPRESSION', 'Avoid RUD')
t.mock.method(compressionsAlgorithms[compression], 'compressSync', () => { throw expectedError })

await rejects(

async () => {
await producer.send({
messages: [{ topic: testTopic, value: Buffer.from('auto-init-idempotent-message') }],
compression,
})
},
(error: any) => {
strictEqual(error instanceof AggregateError, true)
strictEqual(error.errors[0], expectedError)
return true
}
)
})

test('send should validate options in strict mode', async t => {
const producer = createProducer(t, { strict: true })
const testTopic = await createTopic(t)
Expand Down
18 changes: 14 additions & 4 deletions test/network/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -752,17 +752,27 @@ test('Connection should handle request serialization errors', async t => {
throw new Error('Parser error')
}

// Send a request
await throws(() =>
const requestPromise = new Promise((resolve, reject) => {
connection.send(
0, // apiKey
0, // apiVersion
payloadFn as () => Writer,
parser,
false,
false,
() => {}
))
(err: any) => {
if (err) {
reject(err)
}

resolve(null)
}
)
})

await rejects(() => requestPromise, {
message: 'Serialization error'
})

verifyTracingChannel()
})
Expand Down