When comparing with samples, you should consider all possible cases or provide a “backup copy” (case _ => ...). Option can be Some or None , but you only match the None case.
If Session.get().getAttribute("player") returns Some(player) , you will receive a MatchError (exception).
Since your code does not seem to return anything, I would rewrite it without match and just check isEmpty .
if(Option(Session.get().getAttribute("player")).isEmpty) { val player = new Player(user.getEmail, user.getNickname).createOrGet Session.get().setAttribute("player", player) }
Although this is not much different from checking Session.get().getAttribute("player") == null .
source share