Skip to content

KafkaJSDeleteTopicRecordsErrorPartition

reference
1 min readUpdated

Kind: Interface

Source: packages/microservices/external/kafka.interface.ts

Part of: Microservices

KafkaJSDeleteTopicRecordsErrorPartition describes a failed partition result returned while deleting Kafka topic records. It identifies the affected partition, the requested deletion offset, and the underlying KafkaJSError so callers can inspect and handle partition-specific failures.

Properties

PropertyType
partitionnumber
offsetstring
errorKafkaJSError

Diagram

mermaid
graph LR
  Request[Delete topic records request] --> PartitionResult[KafkaJSDeleteTopicRecordsErrorPartition]
  PartitionResult --> Partition[partition: number]
  PartitionResult --> Offset[offset: string]
  PartitionResult --> Error[error: KafkaJSError]
  Error --> Handling[Retry, log, or surface failure]

Usage

ts
import type { KafkaJSError } from 'kafkajs';
import type { KafkaJSDeleteTopicRecordsErrorPartition } from './kafka.interface';

function handleDeleteRecordsFailure(
  failure: KafkaJSDeleteTopicRecordsErrorPartition,
) {
  console.error(
    `Unable to delete records through offset ${failure.offset} ` +
      `for partition ${failure.partition}: ${failure.error.message}`,
  );

  // Use the partition and offset to retry or report the failed operation.
  return {
    partition: failure.partition,
    offset: failure.offset,
    retryable: failure.error.retriable,
  };
}

const failure: KafkaJSDeleteTopicRecordsErrorPartition = {
  partition: 2,
  offset: '1840',
  error: new Error('Broker unavailable') as KafkaJSError,
};

handleDeleteRecordsFailure(failure);

AI Coding Instructions

  • Treat offset as a string; Kafka offsets may exceed JavaScript's safe integer range.
  • Preserve the original KafkaJSError rather than replacing it with a generic error, since it contains Kafka-specific diagnostics and retry metadata.
  • Handle failures per partition instead of assuming a delete-records operation succeeds or fails for the entire topic.
  • Include the partition and offset in logs, metrics, and retry context to make partial failures traceable.

Was this page helpful?

Download as PDF
KafkaJSDeleteTopicRecordsErrorPartition — NestJS head-to-head