Skip to content

Commit

Permalink
Merge pull request #461 from steinybot/st4-npe-workaround
Browse files Browse the repository at this point in the history
Add workaround for NPE
  • Loading branch information
eed3si9n committed Apr 22, 2020
2 parents 3755d20 + d257f79 commit 2fdcbe7
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions library/src/main/scala/g8.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.stringtemplate.v4.misc.STMessage
import scala.collection.mutable
import scala.util.Try
import scala.util.control.Exception.{allCatch, catching}
import scala.util.control.NonFatal

object G8 {
import org.stringtemplate.v4.{AttributeRenderer, ST, STGroup, STErrorListener}
Expand Down Expand Up @@ -131,13 +132,22 @@ object G8 {

val attributes = resolved mapValues AugmentedString.apply

val st = new ST(group, default)

attributes.foreach {
case (k, v) =>
st.add(k, v)
try {
val st = new ST(group, default)
attributes.foreach {
case (k, v) =>
st.add(k, v)
}
st.render()
} catch {
case NonFatal(e: Exception) =>
// This is a workaround for https://github.com/antlr/stringtemplate4/issues/253.
throw new STException(
"An unexpected error occurred while processing the template. " +
"Check that all literal '$' are properly escaped with '\\$'",
e
)
}
st.render()
}

class STErrorHandler extends STErrorListener {
Expand Down

0 comments on commit 2fdcbe7

Please sign in to comment.