1

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!

Haspemulator
  • 11,050
  • 9
  • 49
  • 76

1 Answers1

2

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.

Community
  • 1
  • 1
Alex Yarmula
  • 10,477
  • 5
  • 33
  • 32
  • Hi, thanks for answer. So all the case variables (to the left of =>) have to be named in lowercase? Does this also applies to `get[String]("ExceptionInfo.ExceptionType")`? I mean, should I rename it to `get[String]("ExceptionInfo.exceptionType")`? Or how Anorm matches the strings and those case variables? – Haspemulator Apr 12 '13 at 08:44
  • Correct, case variables need to start in lowercase. It's best to stick to one naming convention, and in Scala it is naming fields with camelCase. As far as database fields, there's more flexibility: it's up to you what you name them. Anorm will just care about the types ([String], [Int], etc) and the order (by "~"). – Alex Yarmula Apr 12 '13 at 13:01