Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Include exception type in StatusReply toString when not text #31963

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -54,6 +54,10 @@ class StatusReplySpec extends AkkaSpec with ScalaFutures {
}
}

"include exception type in toString for non text-error" in {
StatusReply.Error(TestException("boho!")).toString should include("TestException")
}

"transform scala.util.Try" in {
StatusReply.fromTry(scala.util.Success("woho")) should matchPattern {
case StatusReply.Success("woho") =>
Expand Down
6 changes: 4 additions & 2 deletions akka-actor/src/main/scala/akka/pattern/StatusReply.scala
Expand Up @@ -13,6 +13,7 @@ import akka.Done
import akka.actor.InvalidMessageException
import akka.annotation.InternalApi
import akka.dispatch.ExecutionContexts
import akka.pattern.StatusReply.ErrorMessage

/**
* Generic top-level message type for replies that signal failure or success. Convenient to use together with the
Expand Down Expand Up @@ -53,8 +54,9 @@ final class StatusReply[+T] private (private val status: Try[T]) {
override def hashCode(): Int = status.hashCode

override def toString: String = status match {
case ScalaSuccess(t) => s"Success($t)"
case ScalaFailure(ex) => s"Error(${ex.getMessage})"
case ScalaSuccess(t) => s"Success($t)"
case ScalaFailure(ex: ErrorMessage) => s"Error(${ex.getMessage})"
case ScalaFailure(ex) => s"Error(${ex.getClass.getName}: ${ex.getMessage})"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't matter, but an alternative could have been ex.toString, which by default does pretty much the same thing but also handles the case of null message for NPE

}

}
Expand Down