From 6941f53c79bb4ad8adb5ebc4bcc3a3c44d02e353 Mon Sep 17 00:00:00 2001 From: Ivan Topolnjak Date: Tue, 18 Sep 2018 12:19:08 +0200 Subject: use NonFatal instead of plain Throwable when catching exceptions --- kamon-core/src/main/scala/kamon/ContextStorage.scala | 4 +++- kamon-core/src/main/scala/kamon/context/HttpPropagation.scala | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'kamon-core/src/main/scala/kamon') diff --git a/kamon-core/src/main/scala/kamon/ContextStorage.scala b/kamon-core/src/main/scala/kamon/ContextStorage.scala index ee35264a..47d0b567 100644 --- a/kamon-core/src/main/scala/kamon/ContextStorage.scala +++ b/kamon-core/src/main/scala/kamon/ContextStorage.scala @@ -3,6 +3,8 @@ package kamon import kamon.context.{Context, Storage} import kamon.trace.Span +import scala.util.control.NonFatal + trait ContextStorage { private val _contextStorage = Storage.ThreadLocal() @@ -34,7 +36,7 @@ trait ContextStorage { try { withContextKey(Span.ContextKey, span)(f) } catch { - case t: Throwable => + case NonFatal(t) => span.addError(t.getMessage, t) throw t diff --git a/kamon-core/src/main/scala/kamon/context/HttpPropagation.scala b/kamon-core/src/main/scala/kamon/context/HttpPropagation.scala index d225aa28..d53a6250 100644 --- a/kamon-core/src/main/scala/kamon/context/HttpPropagation.scala +++ b/kamon-core/src/main/scala/kamon/context/HttpPropagation.scala @@ -5,6 +5,7 @@ import com.typesafe.config.Config import org.slf4j.LoggerFactory import scala.reflect.ClassTag +import scala.util.control.NonFatal import scala.util.{Failure, Success} /** @@ -145,7 +146,7 @@ object HttpPropagation { }) } } catch { - case t: Throwable => log.warn("Failed to read the context tags header", t.asInstanceOf[Any]) + case NonFatal(t) => log.warn("Failed to read the context tags header", t.asInstanceOf[Any]) } // Tags explicitly mapped on the tags.mappings configuration. @@ -154,7 +155,7 @@ object HttpPropagation { try { reader.readHeader(httpHeader).foreach(tagValue => tags += (tagName -> tagValue)) } catch { - case t: Throwable => log.warn("Failed to read mapped tag [{}]", tagName, t.asInstanceOf[Any]) + case NonFatal(t) => log.warn("Failed to read mapped tag [{}]", tagName, t.asInstanceOf[Any]) } } @@ -165,7 +166,7 @@ object HttpPropagation { try { result = entryDecoder.readEntry(reader, context) } catch { - case t: Throwable => log.warn("Failed to read entry [{}]", entryName.asInstanceOf[Any], t.asInstanceOf[Any]) + case NonFatal(t) => log.warn("Failed to read entry [{}]", entryName.asInstanceOf[Any], t.asInstanceOf[Any]) } result @@ -209,7 +210,7 @@ object HttpPropagation { try { entryWriter.writeEntry(context, writer, direction) } catch { - case t: Throwable => log.warn("Failed to write entry [{}] due to: {}", entryName.asInstanceOf[Any], t.asInstanceOf[Any]) + case NonFatal(t) => log.warn("Failed to write entry [{}] due to: {}", entryName.asInstanceOf[Any], t.asInstanceOf[Any]) } } } -- cgit v1.2.3