Skip to content

Commit

Permalink
Fixed bug in communication error logging when the error message is null
Browse files Browse the repository at this point in the history
Better error handling for generation of communication message JSON
  • Loading branch information
darkfrog26 committed Feb 8, 2019
1 parent af353ac commit b491aeb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import sbtcrossproject.CrossPlugin.autoImport.crossProject

name := "youi"
organization in ThisBuild := "io.youi"
version in ThisBuild := "0.10.4"
version in ThisBuild := "0.10.5-SNAPSHOT"
scalaVersion in ThisBuild := "2.12.8"
crossScalaVersions in ThisBuild := List("2.12.8", "2.11.12")
resolvers in ThisBuild += Resolver.sonatypeRepo("releases")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ class CommunicationInternal private[communication](communication: Communication)
endPoint(message).map { content =>
send := CommunicationMessage(CommunicationMessage.MethodResponse, message.endPoint, message.invocationId, List(content), None)
}.failed.foreach { t =>
send := CommunicationMessage(CommunicationMessage.MethodResponse, message.endPoint, message.invocationId, Nil, Some(t.getMessage))
val error = Option(t.getMessage).orElse(Some("An error occurred"))
send := CommunicationMessage(CommunicationMessage.MethodResponse, message.endPoint, message.invocationId, Nil, error)
communication.error(t)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ case class CommunicationMessage(messageType: Int,
invocationId: Int,
content: List[String],
error: Option[String]) {
lazy val parsableString: String = {
lazy val parsableString: String = try {
val json = JsonUtil.toJsonString(this)
s"|CM|$json"
} catch {
case t: Throwable => throw new RuntimeException(s"Unable to convert $this to JSON", t)
}
}

Expand Down

0 comments on commit b491aeb

Please sign in to comment.