0
votes

I have a small Scala application that's using Akka actors. In the course of doing some refactoring, I've encountered a completely unexpected situation that I've been unable to debug.

I have nodes in a graph that send messages to each other. In fact, they all send messages to a single actor who turns around and directs them back to the appropriate target, but I doubt that's especially relevant.

My "NodeActor" has a receive method:

final def receive: PartialFunction[Any,Unit] = {
  case NInit() => ...
  case NStart() => ...
  case m: Any =>
    log.error(s"Unexpected message: $m")
}

I have started to get the unexpected message error where $m is a bare tuple. It's being sent by the central monitoring actor, but I cannot for the life of me work out how. All of the messages sent by the graph monitor look like properly formatted case class instances. I've attempted unsuccessfully to get Akka to log ever sent and received method.

Eventually, I discovered aroundReceive and implemented a primitive version of that which simply logs the received message. None of the messages that pass through that method are just a bare tuple.

I completely baffled about how to proceed. Suggestions most welcome.

2
The Actor class has a sender method that you can call from the receive function.Dylan

2 Answers

0
votes

I took out the case m: Any case, let the MatchError occur, and reviewed the stack trace. I was literally calling receive() directly from elsewhere due to a cut-and-paste failure-to-think bug. Nevermind.

0
votes

Use sender.path. I normally do

log.error(s"Unexpected message: $m from sender: ${sender.path}")