chia7712 commented on code in PR #20159: URL: https://github.com/apache/kafka/pull/20159#discussion_r2206425362
########## clients/src/main/java/org/apache/kafka/clients/producer/KafkaProducer.java: ########## @@ -1225,7 +1230,9 @@ private ClusterAndWaitTime waitOnMetadata(String topic, Integer partition, long if (metadata.getError(topic) != null) { throw new TimeoutException(errorMessage, metadata.getError(topic).exception()); } - throw new TimeoutException(errorMessage); + if (ex.getCause() != null) + throw new TimeoutException(errorMessage, ex.getCause()); + throw new TimeoutException(errorMessage, new PotentialCauseException("Metadata update timed out ― topic missing, auth denied, broker/partition unavailable, or client sender/buffer stalled.")); Review Comment: thanks for your explanation. I agree that specific exception types could help developer to catch the actual root cause. My question is, do we really need `PotentialCauseException` to be the base exception for `NetworkPotentialCauseException` and `CPUBusyPotentialCauseException`? Perhaps `KafkaException` is good enough. Another exception design uses `TimeoutException` as a parent class, similar to https://github.com/apache/kafka/commit/e032a360708cec2284f714e4cae388066064d61c. The benefit of this is simplifying the code, since developers wouldn't need to check root cause of a `TimeoutException` from root cause of an `ExecutionException` :smile: thanks for bringing up this great discussion. I'd like to see kafka exception hierarchy becomr more developer-friendly. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org