armeria icon indicating copy to clipboard operation
armeria copied to clipboard

Show more stack trace of CompositeException

Open minwoox opened this issue 2 years ago • 7 comments

This is an example stack trace of a CompositeException:

com.linecorp.armeria.common.util.CompositeException: 2 exceptions occurred. 
	at com.linecorp.armeria.common.stream.AbstractStreamMessage$CloseEvent.notifySubscriber(AbstractStreamMessage.java:273)
	at com.linecorp.armeria.common.stream.DefaultStreamMessage.notifySubscriberOfCloseEvent0(DefaultStreamMessage.java:300)
	at com.linecorp.armeria.common.stream.DefaultStreamMessage.lambda$notifySubscriberOfCloseEvent$3(DefaultStreamMessage.java:294)
	at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
	at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:391)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
	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:835)
Caused by: com.linecorp.armeria.common.util.CompositeException$ExceptionOverview: Multiple exceptions (2)
|-- java.util.NoSuchElementException: null
    at java.base/java.util.ArrayDeque.getLast(ArrayDeque.java:413)
|-- com.linecorp.armeria.common.stream.AbortedStreamException: null
    at com.linecorp.armeria.common.stream.AbortedStreamException.get(AbortedStreamException.java:39)

The exceptions in ExceptionOverview just show two lines of stack traces so it's really hard to get a context what's going on from it. We might need to increase the lines (20 is sensible default?) and show full stack trace when -Dcom.linecorp.armeria.verboseExceptions=true.

minwoox avatar Jul 11 '22 04:07 minwoox

Can i solve this issue?

devdynam0507 avatar Jul 14 '22 16:07 devdynam0507

@devdynam0507 Of course, you can. 😄 Thanks in advance.

minwoox avatar Jul 15 '22 03:07 minwoox

Before i begin, I have a question. Is the expected output result like below?

com.linecorp.armeria.common.util.CompositeException: 2 exceptions occurred. 
	at com.linecorp.armeria.common.stream.AbstractStreamMessage$CloseEvent.notifySubscriber(AbstractStreamMessage.java:273)
	at com.linecorp.armeria.common.stream.DefaultStreamMessage.notifySubscriberOfCloseEvent0(DefaultStreamMessage.java:300)
	at com.linecorp.armeria.common.stream.DefaultStreamMessage.lambda$notifySubscriberOfCloseEvent$3(DefaultStreamMessage.java:294)
	at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
	at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:391)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
	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:835)
Caused by: com.linecorp.armeria.common.util.CompositeException$ExceptionOverview: Multiple exceptions (2)
|-- java.util.NoSuchElementException: null
    at java.base/java.util.ArrayDeque.getLast(ArrayDeque.java:413)
// this!
    at java.some/~
    at java.some/~
    at java.some/~
//
    ....
|-- com.linecorp.armeria.common.stream.AbortedStreamException: null
    at com.linecorp.armeria.common.stream.AbortedStreamException.get(AbortedStreamException.java:39)
// this!
    at java.some/~
    at java.some/~
    at java.some/~
//
    ....

devdynam0507 avatar Jul 15 '22 04:07 devdynam0507

Yes, exactly. 😉 We need to:

  • show more lines (20?) of the stack trace by default.
  • show the full stack trace when the system property is enabled.

minwoox avatar Jul 15 '22 05:07 minwoox

thanks for explain 😃 i have a one idea, How about printing 20 lines (or other) by default and allowing the user to set the number of lines that are output?

devdynam0507 avatar Jul 15 '22 05:07 devdynam0507

allowing the user to set the number of lines that are output?

That's a good suggestion. 👍 However, I'm a bit reluctant to do that because

  • CompositeException is not something that users create by themselves
  • We need another system property flag to indicate the number of lines which adds another public API that might not be needed.

Therefore, how about just using the verboseExceptions property for now? If there're demands for the number of lines later, we can add it at that time. 😄

minwoox avatar Jul 15 '22 05:07 minwoox

I understood correctly! I will start working on this soon

devdynam0507 avatar Jul 15 '22 05:07 devdynam0507