Question

There should be something simple here, though I'm completely missing it, since I'm noob in Scala and Play. Here's the code:

case class ExceptionInfo(ExceptionType: String, Message: String, StackTrace: Seq[String])

object ExceptionInfo
    {
      val excInfoParser = {
        get[String]("ExceptionInfo.ExceptionType") ~ 
        get[String]("Message") ~ 
        get[String]("ExceptionInfo.StackTrace") map {
          case ExceptionType ~ Message ~ StackTrace => ExceptionInfo(ExceptionType, Message, StackTrace.split("\r\n"))
        }
      }
    }

This doesn't compile, with following output:

Description Resource            Path                Location                        Type
not found: value ExceptionType  Application.scala   /testme/app/controllers line 40 Scala Problem
not found: value Message        Application.scala   /testme/app/controllers line 40 Scala Problem
not found: value StackTrace     Application.scala   /testme/app/controllers line 40 Scala Problem
not found: value ExceptionType  Application.scala   /testme/app/controllers line 40 Scala Problem

Thanks in advance!

Was it helpful?

Solution

Should work when you name the variables in lowercase:

case exceptionType ~ message ~ stackTrace => ExceptionInfo(exceptionType, message, stackTrace.split("\r\n"))

The lowercase is what distinguishes variables to be bound to (what you're looking for) from constants to be matched against. See here and here for more.

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