diff --git a/src/main/scala/com/sky/kafka/topicloader/config/config.scala b/src/main/scala/com/sky/kafka/topicloader/config/config.scala index dd8b2b98..52b22230 100644 --- a/src/main/scala/com/sky/kafka/topicloader/config/config.scala +++ b/src/main/scala/com/sky/kafka/topicloader/config/config.scala @@ -5,18 +5,20 @@ import cats.implicits._ import com.typesafe.config.ConfigException import scala.util.Try +import scala.util.control.NonFatal package object config { type ValidationResult[A] = ValidatedNec[ConfigException, A] implicit class TryOps[A](t: Try[A]) { - def validate(path: String): ValidationResult[A] = t.toEither.validate(path) - } - - implicit class EitherOps[A](e: Either[Throwable, A]) { - def validate(path: String): ValidationResult[A] = e.leftMap { + private[topicloader] def validate(path: String): ValidationResult[A] = t.toEither.leftMap { case ce: ConfigException => ce - case e: Throwable => new ConfigException.BadValue(path, e.getMessage) + case NonFatal(e) => new ConfigException.BadValue(path, e.getMessage) }.toValidatedNec } + + implicit class EitherOps[A](e: Either[IllegalArgumentException, A]) { + private[topicloader] def validate(path: String): ValidationResult[A] = + e.leftMap(e => new ConfigException.BadValue(path, e.getMessage)).toValidatedNec + } } diff --git a/src/test/scala/integration/TopicLoaderIntSpec.scala b/src/test/scala/integration/TopicLoaderIntSpec.scala index 4f333708..acbb5885 100644 --- a/src/test/scala/integration/TopicLoaderIntSpec.scala +++ b/src/test/scala/integration/TopicLoaderIntSpec.scala @@ -291,7 +291,7 @@ class TopicLoaderIntSpec extends IntegrationSpecBase { config.topicLoader.bufferSize.value shouldBe 10 } - "fail to load a valid config" in new TestContext { + "fail to load an invalid config" in new TestContext { override implicit lazy val system: ActorSystem = ActorSystem( "test-actor-system", ConfigFactory.parseString(