Question

In our Scala, Play, Reactivemongo we have a big problem with exception handling - when there is an error, in Iteratee/Enumeratee or in Actor system Play just swallows it, without logging any error to the output. So we effectively need to guess where, and why this error might happen.

We made Globals override, to always print the error, and specified logger.root=TRACE, but still saw no output, from which we could analyse our problems.

How to forcebly make Play print all the errors

Was it helpful?

Solution 3

At the solution I used, is override through ErrorHandling in Play https://www.playframework.com/documentation/2.4.2/ScalaErrorHandling, basically creating ErrorHandler that logs all the errors, with needed detalization.

OTHER TIPS

Didn't found the way to explicitly log everything but there is a way to log exceptions locally.

I did this:

def recover[T] = Enumeratee.recover[T] {
  case (e, input) => Logger.error("Error happened on:" + input, e)
}

and then used it on all the enumeratees that can produce errors

def transform(from: Enumerator[From]): Enumerator[String] = {
  heading >>> (from &> recover[From] ><> mapper) >>> tailing
}

here, mapper throws exception, and they are all logged.

I think your problem is with how Future works in scala, let's take the following exemple :

val f :Future[Int]= Future {
     throw new NullPointerException("NULL")
     1
}
f.map(s1 => {println(s" ==>  $s1");s" ==>  $s1"})

This code will throw an exception but the stack trace will not be printed as futures handle the error.

If you want to get the error that happened you can just call:

f.onComplete{
    case Success(e) => {}
    case Failure(e) => e.printStackTrace()
}

e is a throwable that you can use as you want to handle the error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top