AS-5201: include topic name in all exceptions#198
Conversation
|
do we have any racing condition that a thread could handle different topics ? I am worried that this thread local topic could wrongly print topic name while handling other topics. If there is any async operation(perhaps this can be introduced in the future) in the try/finally block, the thread context lifecycle management will become more complex, and it would be hard to trace. I think we better just directly pass topicName in the target code block (from the stack) without this thread local context. plz update the description to explain more about this change. |
|
Instead of using thread-local to store the topic, we now pass the topic name directly where the code runs. This avoids confusion and wrong values when multiple threads are involved. Created a common method to handle all exceptions. Updated Utils.java: Modified method signature to handleException(Throwable cause, String topic) to include topic context.
This method: Also added wrapper methods so that: we don’t need to write try-catch everywhere, and all errors automatically go through this common handling. |
| @@ -53,25 +53,43 @@ | |||
| public final class Utils { | |||
| private Utils() {} | |||
|
|
|||
There was a problem hiding this comment.
Add this overloaded func and use this func if topic is unknown, instead of directly calling handleException(e, null),
public static JMSException handleException(Throwable cause) {
return handleException(cause, null);
}|
|
||
| final class ConsumerConfigurationTest { | ||
| @RegisterExtension | ||
| static PulsarContainerExtension pulsarContainer = new PulsarContainerExtension(); |
There was a problem hiding this comment.
why this is required? remove it
| <dependency> | ||
| <groupId>org.testcontainers</groupId> | ||
| <artifactId>junit-jupiter</artifactId> | ||
| <version>${testcontainers.version}</version> |
| </executions> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-assembly-plugin</artifactId> |
| try { | ||
| return code.getAsBoolean(); | ||
| } catch (Throwable err) { | ||
| throw handleException(err, topic); |
There was a problem hiding this comment.
why adding try/catch here?
| return buildMessage(safeMsg(t), topic); | ||
| } | ||
|
|
||
| public static <T> T executeWithTopic(String topic, SupplierWithException<T> code) |
There was a problem hiding this comment.
remove funcs if not required.
| if (message == null) { | ||
| return null; | ||
| String topic = destination != null ? destination.getName() : null; | ||
| try { |
| PulsarDestination dest = PulsarConnectionFactory.toPulsarDestination(destination); | ||
| String topicName = factory.getPulsarTopicName(dest); | ||
| String subscriptionName = factory.getQueueSubscriptionName(dest); | ||
| try { |
| throws JMSException { | ||
| PulsarDestination dest = PulsarConnectionFactory.toPulsarDestination(destination); | ||
| String topicName = factory.getPulsarTopicName(dest); | ||
| try { |
| validateSelector(enableFilters, selector); | ||
| PulsarDestination dest = PulsarConnectionFactory.toPulsarDestination(destination); | ||
| String topicName = factory.getPulsarTopicName(dest); | ||
| try { |
| throw Utils.handleException(error, topicName); | ||
|
|
||
| } catch (Throwable t) { | ||
| throw Utils.handleException(t, topicName); |
| <maven.antrun.plugin.version>3.1.0</maven.antrun.plugin.version> | ||
| <snakeyaml.version>2.0</snakeyaml.version> | ||
| <testcontainers.version>1.20.4</testcontainers.version> | ||
| <testcontainers.version>1.21.4</testcontainers.version> |
There was a problem hiding this comment.
why change here? revert it this is not the scope in this PR
|
plz not move try/catch lines. |
heesung-sohn
left a comment
There was a problem hiding this comment.
And lets not cover all exception cases in this PR.
Lets scope this PR to the specific case that the customer is complaining. Can you pinpoint the code path according the customer error logs?
In general, pulsar client tries to print topic name from its exception.
No description provided.