From 887a5a86c7eef30861cd752ada1a6aa3c454d84a Mon Sep 17 00:00:00 2001 From: David Francoeur Date: Tue, 4 Apr 2023 11:21:50 -0400 Subject: [PATCH] Fallback to Json.Null if getMessage is null --- modules/log/shared/src/main/scala/LogSpan.scala | 2 +- modules/log/shared/src/test/scala/LogSuite.scala | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/log/shared/src/main/scala/LogSpan.scala b/modules/log/shared/src/main/scala/LogSpan.scala index f5621a17..d8cb3419 100644 --- a/modules/log/shared/src/main/scala/LogSpan.scala +++ b/modules/log/shared/src/main/scala/LogSpan.scala @@ -75,7 +75,7 @@ private[log] final case class LogSpan[F[_]: Sync: Logger]( putAny( "exit.case" -> "error".asJson, "exit.error.class" -> err.getClass.getName.asJson, - "exit.error.message" -> err.toString.asJson, // toString handles null message + "exit.error.message" -> Option(err.getMessage).map(_.asJson).getOrElse(Json.Null), "exit.error.stackTrace" -> err.getStackTrace.map(_.toString).asJson ) *> put(fields: _*) diff --git a/modules/log/shared/src/test/scala/LogSuite.scala b/modules/log/shared/src/test/scala/LogSuite.scala index a4115800..dc69306c 100644 --- a/modules/log/shared/src/test/scala/LogSuite.scala +++ b/modules/log/shared/src/test/scala/LogSuite.scala @@ -105,7 +105,7 @@ class LogSuite extends CatsEffectSuite { | ], | "exit.case" : "succeeded", | "exit.error.class" : "java.lang.RuntimeException", - | "exit.error.message" : "java.lang.RuntimeException: oops", + | "exit.error.message" : "oops", | "children" : [ | ] |} @@ -118,7 +118,7 @@ class LogSuite extends CatsEffectSuite { | ], | "exit.case" : "succeeded", | "exit.error.class" : "java.lang.RuntimeException", - | "exit.error.message" : "java.lang.RuntimeException", + | "exit.error.message" : null, | "children" : [ | ] |}