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 2 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
4 changes: 3 additions & 1 deletion src/main/scala/com/sky/kafka/topicloader/config/config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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]
Expand All @@ -16,7 +17,8 @@ package object config {
implicit class EitherOps[A](e: Either[Throwable, A]) {
lacarvalho91 marked this conversation as resolved.
Show resolved Hide resolved
def validate(path: String): ValidationResult[A] = e.leftMap {
case ce: ConfigException => ce
case e: Throwable => new ConfigException.BadValue(path, e.getMessage)
case e if NonFatal(e) => new ConfigException.BadValue(path, e.getMessage)
bcarter97 marked this conversation as resolved.
Show resolved Hide resolved
case e: Throwable => throw e
}.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