eolivelli opened a new pull request #14620:
URL: https://github.com/apache/pulsar/pull/14620


   ### Motivation
   When you run Pulsar Admin API functions the stacktrace of the error is not 
user friendly as it does not report the stacktrace of the caller method, but 
usually it is the stacktrace of another thread (because requests are handled in 
the REST Client thread pool).
   
   ### Modifications
   
   With this change all the PulsarAdminExceptions will be cloned, grabbing the 
current thread stacktrace, and then thrown.
   The "cause" is preserved, and we are adding as "suppressed exception" the 
original exception.
   
   ### Verifying this change
   
   This change is already covered by existing tests
   
   ### Results:
   
   This is an example of a application that calls "tenants.delete()" in a 
main() method in a class AdminTest, at line 52:
   
   Before:
   ```
   org.apache.pulsar.client.admin.PulsarAdminException$NotFoundException: 
Tenant doesn't exist
        at 
org.apache.pulsar.client.admin.internal.BaseResource.getApiException(BaseResource.java:230)
        at 
org.apache.pulsar.client.admin.internal.BaseResource$3.failed(BaseResource.java:184)
        at 
org.glassfish.jersey.client.JerseyInvocation$1.failed(JerseyInvocation.java:882)
        at 
org.glassfish.jersey.client.JerseyInvocation$1.completed(JerseyInvocation.java:863)
        at 
org.glassfish.jersey.client.ClientRuntime.processResponse(ClientRuntime.java:229)
        at 
org.glassfish.jersey.client.ClientRuntime.access$200(ClientRuntime.java:62)
        at 
org.glassfish.jersey.client.ClientRuntime$2.lambda$response$0(ClientRuntime.java:173)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
        at 
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:288)
        at 
org.glassfish.jersey.client.ClientRuntime$2.response(ClientRuntime.java:173)
        at 
org.apache.pulsar.client.admin.internal.http.AsyncHttpConnector.lambda$apply$1(AsyncHttpConnector.java:228)
        at 
java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859)
        at 
java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:837)
        at 
java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
        at 
java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2073)
        at 
org.apache.pulsar.client.admin.internal.http.AsyncHttpConnector.lambda$retryOperation$4(AsyncHttpConnector.java:270)
        at 
java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859)
        at 
java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:837)
        at 
java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
        at 
java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2073)
        at 
org.asynchttpclient.netty.NettyResponseFuture.loadContent(NettyResponseFuture.java:222)
        at 
org.asynchttpclient.netty.NettyResponseFuture.done(NettyResponseFuture.java:257)
        at 
org.asynchttpclient.netty.handler.AsyncHttpClientHandler.finishUpdate(AsyncHttpClientHandler.java:241)
        at 
org.asynchttpclient.netty.handler.HttpHandler.handleChunk(HttpHandler.java:114)
        at 
org.asynchttpclient.netty.handler.HttpHandler.handleRead(HttpHandler.java:143)
        at 
org.asynchttpclient.netty.handler.AsyncHttpClientHandler.channelRead(AsyncHttpClientHandler.java:78)
        at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
        at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
        at 
io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
        at 
io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
        at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
        at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
        at 
io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
        at 
io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
        at 
io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
        at 
io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
        at 
io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
        at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
        at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
        at 
io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
        at 
io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
        at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
        at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
        at 
io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
        at 
io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
        at 
io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
        at 
io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
        at 
io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
        at 
io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
        at 
io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at 
io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:829)
   Caused by: javax.ws.rs.NotFoundException: HTTP 404 Not Found
        at 
org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:948)
        at 
org.glassfish.jersey.client.JerseyInvocation.access$700(JerseyInvocation.java:82)
        ... 54 more
   ```
   
   After (you can see the original code AdminTest.main(AdminTest.java:52))
   ```
   org.apache.pulsar.client.admin.PulsarAdminException$NotFoundException: 
Tenant doesn't exist
        at 
org.apache.pulsar.client.admin.PulsarAdminException.wrap(PulsarAdminException.java:252)
        at 
org.apache.pulsar.client.admin.internal.BaseResource.sync(BaseResource.java:302)
        at 
org.apache.pulsar.client.admin.internal.TenantsImpl.deleteTenant(TenantsImpl.java:114)
        at AdminTest.main(AdminTest.java:52)
        Suppressed: 
org.apache.pulsar.client.admin.PulsarAdminException$NotFoundException: Tenant 
doesn't exist
                at 
org.apache.pulsar.client.admin.internal.BaseResource.getApiException(BaseResource.java:234)
                at 
org.apache.pulsar.client.admin.internal.BaseResource$3.failed(BaseResource.java:188)
                at 
org.glassfish.jersey.client.JerseyInvocation$1.failed(JerseyInvocation.java:882)
                at 
org.glassfish.jersey.client.JerseyInvocation$1.completed(JerseyInvocation.java:863)
                at 
org.glassfish.jersey.client.ClientRuntime.processResponse(ClientRuntime.java:229)
                at 
org.glassfish.jersey.client.ClientRuntime.access$200(ClientRuntime.java:62)
                at 
org.glassfish.jersey.client.ClientRuntime$2.lambda$response$0(ClientRuntime.java:173)
                at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
                at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
                at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
                at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
                at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
                at 
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:288)
                at 
org.glassfish.jersey.client.ClientRuntime$2.response(ClientRuntime.java:173)
                at 
org.apache.pulsar.client.admin.internal.http.AsyncHttpConnector.lambda$apply$1(AsyncHttpConnector.java:228)
                at 
java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859)
                at 
java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:837)
                at 
java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
                at 
java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2073)
                at 
org.apache.pulsar.client.admin.internal.http.AsyncHttpConnector.lambda$retryOperation$4(AsyncHttpConnector.java:270)
                at 
java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859)
                at 
java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:837)
                at 
java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
                at 
java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2073)
                at 
org.asynchttpclient.netty.NettyResponseFuture.loadContent(NettyResponseFuture.java:222)
                at 
org.asynchttpclient.netty.NettyResponseFuture.done(NettyResponseFuture.java:257)
                at 
org.asynchttpclient.netty.handler.AsyncHttpClientHandler.finishUpdate(AsyncHttpClientHandler.java:241)
                at 
org.asynchttpclient.netty.handler.HttpHandler.handleChunk(HttpHandler.java:114)
                at 
org.asynchttpclient.netty.handler.HttpHandler.handleRead(HttpHandler.java:143)
                at 
org.asynchttpclient.netty.handler.AsyncHttpClientHandler.channelRead(AsyncHttpClientHandler.java:78)
                at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
                at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
                at 
io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
                at 
io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
                at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
                at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
                at 
io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
                at 
io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
                at 
io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:327)
                at 
io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:299)
                at 
io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
                at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
                at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
                at 
io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
                at 
io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
                at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
                at 
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
                at 
io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
                at 
io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
                at 
io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722)
                at 
io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658)
                at 
io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584)
                at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
                at 
io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
                at 
io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
                at 
io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
                at java.base/java.lang.Thread.run(Thread.java:829)
        Caused by: javax.ws.rs.NotFoundException: HTTP 404 Not Found
                at 
org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:948)
                at 
org.glassfish.jersey.client.JerseyInvocation.access$700(JerseyInvocation.java:82)
                ... 54 more
   Caused by: [CIRCULAR REFERENCE: javax.ws.rs.NotFoundException: HTTP 404 Not 
Found]
   
   ```
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to