Hi,
I have caused a NonLocalReturnControl runtime error by explicitly, superfluously, and unintentionally returning a value within this function
private def foo(data: DataObject): Future[ReadyData] = {
implicit val context = play.api.libs.concurrent.Execution.Implicits.defaultContext
data.Get flatMap { _ match {
case Ready(dataID) => {
return Future { ExecutedData(data, data.access) } // culprit line
}
case NotReady(_) => {
create(data)
}
}
}
}
I have read all over about this type of runtime error, but am still in need of an authoritative explanation about it; is it specific to futures mapping constructs, or is it something more general concerning the nesting of closures? my guess would be it's nonsensical to return from within a future's map block, but something about the type of the error tells me it's more general than that.
In addition it is mentioned in
http://docs.scala-lang.org/sips/completed/futures-promises.html in a vague way as receiving some special treatment, the specialty of which I could not infer there, which connects nicely to the following greater awkwardness I encountered over it:
there was no stack trace to be found in the play log file (nor on the console). Only:
2015-03-14 16:48:51,484 - [ERROR] - from akka.actor.ActorSystemImpl in play-akka.actor.default-dispatcher-4
Uncaught error from thread [play-akka.actor.default-dispatcher-3]
scala.runtime.NonLocalReturnControl: null
Usually, play isn't shy in spilling out the full stack traces....
I attached a debugger to home in on the location of the error. There was definitely a stack at the time/location where the debugger hit a NonLocalReturnControl, but this didn't make it to the log/console. I found that a bit odd, so I am wondering what have I been missing for getting to the stack trace without a joyful remote debugger session.
Thanks in advance!
Matan