From 3cc7e27807571913e526aa73bb56a2cca1ac67af Mon Sep 17 00:00:00 2001 From: Jeff Widman Date: Thu, 7 Dec 2017 12:58:28 -0800 Subject: [PATCH] Raise non-API exceptions The original intent was to catch API exceptions (errors returned by the broker when trying to produce a message) and delegate them to the messages' futures. This is copied from the Java producer. However, we were accidentally catching all exceptions, thereby hiding exceptions from users unless they explicitly check the result of the future. Much better to raise client-side errors directly in the foreground so the user is immediately aware of them and can decide how to handle. Fix #1274 --- kafka/producer/kafka.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/kafka/producer/kafka.py b/kafka/producer/kafka.py index 646e77384..b1796b394 100644 --- a/kafka/producer/kafka.py +++ b/kafka/producer/kafka.py @@ -571,11 +571,7 @@ def send(self, topic, value=None, key=None, partition=None, timestamp_ms=None): # handling exceptions and record the errors; # for API exceptions return them in the future, # for other exceptions raise directly - except Errors.KafkaTimeoutError: - raise - except AssertionError: - raise - except Exception as e: + except Errors.BrokerResponseError as e: log.debug("Exception occurred during message send: %s", e) return FutureRecordMetadata( FutureProduceResult(TopicPartition(topic, partition)),