From 6d840db10c11a86d7288dd99c80e08798c375f53 Mon Sep 17 00:00:00 2001 From: Ben Plommer Date: Tue, 20 Apr 2021 09:41:50 +0100 Subject: [PATCH 1/2] Preserve original exception when converting to AvroError --- modules/core/src/main/scala/vulcan/AvroError.scala | 9 +++++++-- modules/core/src/main/scala/vulcan/AvroException.scala | 7 ++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/core/src/main/scala/vulcan/AvroError.scala b/modules/core/src/main/scala/vulcan/AvroError.scala index 30680d3f..40042a5e 100644 --- a/modules/core/src/main/scala/vulcan/AvroError.scala +++ b/modules/core/src/main/scala/vulcan/AvroError.scala @@ -275,6 +275,11 @@ object AvroError { s"Symbol $symbol is not part of schema symbols [${symbols.mkString(", ")}]" } - private[vulcan] final def fromThrowable(throwable: Throwable): AvroError = - AvroError(throwable.toString) + private[vulcan] final def fromThrowable(cause: Throwable): AvroError = { + new AvroError { + def message: String = cause.toString + + def throwable: Throwable = AvroException(message, Some(cause)) + } + } } diff --git a/modules/core/src/main/scala/vulcan/AvroException.scala b/modules/core/src/main/scala/vulcan/AvroException.scala index c939d23d..2107fe25 100644 --- a/modules/core/src/main/scala/vulcan/AvroException.scala +++ b/modules/core/src/main/scala/vulcan/AvroException.scala @@ -10,11 +10,12 @@ package vulcan * `Throwable` representation of an [[AvroError]], * created with [[AvroError#throwable]]. */ -sealed abstract class AvroException(message: String) extends RuntimeException(message) +sealed abstract class AvroException(message: String, cause: Option[Throwable]) + extends RuntimeException(message, cause.orNull) private[vulcan] object AvroException { - final def apply(message: String): AvroException = - new AvroException(message) { + final def apply(message: String, cause: Option[Throwable] = None): AvroException = + new AvroException(message, cause) { override final def toString: String = s"vulcan.AvroException: $getMessage" } From b8171fba587caaf8302c93c4181467a49668f0bf Mon Sep 17 00:00:00 2001 From: Ben Plommer Date: Tue, 20 Apr 2021 09:46:45 +0100 Subject: [PATCH 2/2] Mima exclusions --- build.sbt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index fdb1b502..21d3cd7f 100644 --- a/build.sbt +++ b/build.sbt @@ -279,7 +279,8 @@ lazy val mimaSettings = Seq( ProblemFilters.exclude[IncompatibleSignatureProblem]("*"), ProblemFilters.exclude[DirectMissingMethodProblem]("vulcan.Codec.withDecodingTypeName"), ProblemFilters.exclude[DirectMissingMethodProblem]("vulcan.AvroError.decode*"), - ProblemFilters.exclude[DirectMissingMethodProblem]("vulcan.AvroError.encode*") + ProblemFilters.exclude[DirectMissingMethodProblem]("vulcan.AvroError.encode*"), + ProblemFilters.exclude[DirectMissingMethodProblem]("vulcan.AvroException.*") ) // format: on }