Skip to content

AS-5201: include topic name in all exceptions#198

Open
Rutuja-IBM wants to merge 3 commits into
masterfrom
AS-5201-include-topicName-in-all-exceptions
Open

AS-5201: include topic name in all exceptions#198
Rutuja-IBM wants to merge 3 commits into
masterfrom
AS-5201-include-topicName-in-all-exceptions

Conversation

@Rutuja-IBM
Copy link
Copy Markdown
Collaborator

No description provided.

@Rutuja-IBM Rutuja-IBM changed the title As 5201 include topic name in all exceptions AS-5201: include topic name in all exceptions Apr 9, 2026
Comment thread pulsar-jms/src/main/java/com/datastax/oss/pulsar/jms/Utils.java
@heesung-sohn
Copy link
Copy Markdown
Collaborator

heesung-sohn commented Apr 13, 2026

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.

@Rutuja-IBM
Copy link
Copy Markdown
Collaborator Author

Rutuja-IBM commented Apr 14, 2026

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.

  • Updated all calling classes to pass the topic as an argument wherever handleException is used.
  • When available, the topic is passed (topic name, fully qualified domain name, or Pulsar topic).
  • When not available or not required, "null" is passed.

This method:
finds the real error, converts it into a JMSException, and adds the topic name to the error message.

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() {}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this is required? remove it

Comment thread pulsar-jms/pom.xml
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${testcontainers.version}</version>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove it.

Comment thread pulsar-jms/pom.xml
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove it.

try {
return code.getAsBoolean();
} catch (Throwable err) {
throw handleException(err, topic);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why adding try/catch here?

return buildMessage(safeMsg(t), topic);
}

public static <T> T executeWithTopic(String topic, SupplierWithException<T> code)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove funcs if not required.

if (message == null) {
return null;
String topic = destination != null ? destination.getName() : null;
try {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why add try?

PulsarDestination dest = PulsarConnectionFactory.toPulsarDestination(destination);
String topicName = factory.getPulsarTopicName(dest);
String subscriptionName = factory.getQueueSubscriptionName(dest);
try {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why move try?

throws JMSException {
PulsarDestination dest = PulsarConnectionFactory.toPulsarDestination(destination);
String topicName = factory.getPulsarTopicName(dest);
try {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why move try?

validateSelector(enableFilters, selector);
PulsarDestination dest = PulsarConnectionFactory.toPulsarDestination(destination);
String topicName = factory.getPulsarTopicName(dest);
try {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why move try?

throw Utils.handleException(error, topicName);

} catch (Throwable t) {
throw Utils.handleException(t, topicName);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why catch?

Comment thread pom.xml
<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>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change here? revert it this is not the scope in this PR

@heesung-sohn
Copy link
Copy Markdown
Collaborator

plz not move try/catch lines.
dont add additional catch unless required.

Copy link
Copy Markdown
Collaborator

@heesung-sohn heesung-sohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants