spray / twirl

The Play framework Scala template engine, stand-alone and packaged as an SBT plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NoSuchElementException during twirl compilation

jlupien opened this issue · comments

There's a bug that existed in Play where the template compiler throws a NoSuchElement exception when trying to access the left projection of an Either$RightProjection. A fix was pulled into Play 2.0, and I'd like to port it to twirl.

The stack trace looks like this:

java.util.NoSuchElementException: Either.left.value on Right
    at scala.Either$LeftProjection.get(Either.scala:287)
    at twirl.compiler.TwirlCompiler$TemplateAsFunctionCompiler$TreeCreationMethods$class.treeFrom(TwirlCompiler.scala:638)
    at twirl.compiler.TwirlCompiler$TemplateAsFunctionCompiler$PresentationCompiler$.treeFrom(TwirlCompiler.scala:645)
    at twirl.compiler.TwirlCompiler$TemplateAsFunctionCompiler$TreeCreationMethods$class.treeFrom(TwirlCompiler.scala:623)
    at twirl.compiler.TwirlCompiler$TemplateAsFunctionCompiler$PresentationCompiler$.treeFrom(TwirlCompiler.scala:645)
    at twirl.compiler.TwirlCompiler$TemplateAsFunctionCompiler$.getFunctionMapping(TwirlCompiler.scala:549)
    at twirl.compiler.TwirlCompiler$.generateFinalTemplate(TwirlCompiler.scala:488)
    at twirl.compiler.TwirlCompiler$.compile(TwirlCompiler.scala:186)
    at twirl.sbt.TemplateCompiler$$anonfun$compile$3.apply(TemplateCompiler.scala:46)
    at twirl.sbt.TemplateCompiler$$anonfun$compile$3.apply(TemplateCompiler.scala:44)
    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:60)
    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
    at twirl.sbt.TemplateCompiler$.compile(TemplateCompiler.scala:44)
    at twirl.sbt.TwirlPlugin$Twirl$$anonfun$settings$4.apply(TwirlPlugin.scala:50)
    at twirl.sbt.TwirlPlugin$Twirl$$anonfun$settings$4.apply(TwirlPlugin.scala:50)
etc

References:
Play 2.0 bug report - for some reason it was never resolved
Play 2.0 github pull request - this has a fix
[Google Search](scala.tools.nsc.interactive.FreshRunReq play) - many reports of the same issue

The fix is in our fork at commit 63ba035. We tested locally.

Fixed as part of #16 and released in 0.7.0.