Skip to content

Commit

Permalink
Catch only non-fatal errors loading config (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcarter97 authored Feb 28, 2022
1 parent 98fe20b commit 86257a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/main/scala/com/sky/kafka/topicloader/config/config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion src/test/scala/integration/TopicLoaderIntSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 86257a8

Please sign in to comment.