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

Runtime hangs when deriving a config using given in Scala 3 #1170

Open
beneyal opened this issue May 23, 2023 · 0 comments
Open

Runtime hangs when deriving a config using given in Scala 3 #1170

beneyal opened this issue May 23, 2023 · 0 comments

Comments

@beneyal
Copy link

beneyal commented May 23, 2023

Hello,

I came across a problem with the following simplified code:

//> using dep "dev.zio::zio-config:4.0.0-RC16"
//> using dep "dev.zio::zio-config-magnolia:4.0.0-RC16"
//> using dep "dev.zio::zio-config-typesafe:4.0.0-RC16"
//> using dep "dev.zio::zio:2.0.13"

import zio.*
import zio.config.*
import zio.config.magnolia.*
import zio.config.typesafe.*

import java.io.File

object ZioConfig {
  final case class RootConfig(myConfig: MyConfig)
  final case class MyConfig(dataDir: File)

  given DeriveConfig[File] = DeriveConfig[String].map(new File(_))

  val configZio: ZIO[Any, Throwable, MyConfig] =
    for {
      configFile <- ZIO.readFile("my-config.conf")
      config <- ConfigProvider
        .fromHoconString(configFile)
        .load(deriveConfig[RootConfig].mapKey(toKebabCase))
        .map(_.myConfig)
    } yield config

  val config: MyConfig = Unsafe.unsafe { implicit unsafe =>
    Runtime.default.unsafe.run(configZio).getOrThrowFiberFailure()
  }

  @main def main: Unit = println(config)
}

Running this code will hang indefinitely without an error. The cause seems to be the given. Replacing it with implicit def solves the hanging issue (implicit val doesn't).

Config file looks like this:

my-config {
  # all data related to odinson is stored here
  data-dir = ${HOME}/foo
}

Am I doing something wrong, or is that a bug?

Thanks for a wonderful library! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant