Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Better" scala stack traces

Scala stack traces are complex, mostly because of the way anonymous functions are translated to bytecode. Here's a example:

java.lang.IllegalStateException
    at com.company.IdentityVerifier$$anonfun$go$2$$anonfun$apply$2.apply$mcII$sp(IdentityVerifier.scala:19)
    at com.company.IdentityVerifier$$anonfun$go$2$$anonfun$apply$2.apply(IdentityVerifier.scala:17)
    at com.company.IdentityVerifier$$anonfun$go$2$$anonfun$apply$2.apply(IdentityVerifier.scala:17)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.immutable.List.foreach(List.scala:318)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
    at scala.collection.AbstractTraversable.map(Traversable.scala:105)
    at com.company.IdentityVerifier$$anonfun$go$2.apply(IdentityVerifier.scala:17)
    at com.company.IdentityVerifier$$anonfun$go$2.apply(IdentityVerifier.scala:16)
    at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:251)
    at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:251)
    at scala.collection.immutable.List.foreach(List.scala:318)
    at scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:251)
    at scala.collection.AbstractTraversable.flatMap(Traversable.scala:105)
    at com.company.IdentityVerifier$.go(IdentityVerifier.scala:16)
    at com.company.UserMap.setLastUserId(UserMap.scala:12)
    at com.company.UserConsumer.setCurrentUser(UserConsumer.java:69)
    at com.company.UserConsumer.consume(UserConsumer.java:64)
    at com.company.UserProducer.execute(UserProducer.java:19)
    at com.company.UserCreator.execute(UserCreator.java:18)
    at com.company.UserCreatorMain$1.run(UserCreatorMain.java:37)
    at com.company.UserCreatorMain.main(UserCreatorMain.java:51)

I've found stackifier (it's their example), but it's a pain to keep pasting stack traces to a webpage. Is there a way to print "better" stack traces automatically?

like image 320
loopbackbee Avatar asked Dec 13 '13 12:12

loopbackbee


People also ask

Should stack traces be logged?

Logging the stack traces of runtime exceptions assists developers in diagnosing runtime failures. However, unnecessary logging of exception stack traces can have many negative impacts such as polluting log files.

What is the difference between call stack and stack trace?

A call stack is typically "the current stack of operations" - i.e. while it's running. A stack trace is typically a copy of the call stack which is logged at some sort of failure, e.g. an exception.

Is stack trace top to bottom?

The first line in the call stack represents the last executed function call, so remember to always read a stack trace top-down.


1 Answers

Intellij IDEA helps, even in the case you are not debugging the code (and the scala plugin should work even with the community version) :

http://www.jetbrains.com/idea/webhelp/analyzing-external-stacktraces.html

You get a clickable stack trace that jumps to the right place.

I asked at ScalaIDE forums whether ScalaIDE does this too. Mirco Dotta ninja-responded:

Yes it does, but it's not the simplest feature to find in Eclipse. You need to open the "Java StackTrace Console"

Haven't asked about emacs, somebody please chip in.

Also, please try to consider that "cryptic" names (go see c++ name mangling) is a price you pay for added flexibility.

like image 97
Miloslav Raus Avatar answered Oct 01 '22 12:10

Miloslav Raus