spray / twirl

The Play framework Scala template engine, stand-alone and packaged as an SBT plugin
Apache License 2.0
215 stars 20 forks source link

NoSuchElementException during twirl compilation #11

Closed jlupien closed 10 years ago

jlupien commented 11 years ago

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

jlupien commented 11 years ago

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

jrudolph commented 10 years ago

Fixed as part of #16 and released in 0.7.0.