loopbackbee
loopbackbee

Reputation: 23322

"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?

Upvotes: 11

Views: 1759

Answers (1)

Miloslav Raus
Miloslav Raus

Reputation: 767

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.

Upvotes: 5

Related Questions