Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch only non-fatal errors loading config #97

Merged
merged 4 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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