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

ZIO's WithRun#runContext fails with an error #1236

Open
skelantros opened this issue Apr 11, 2024 · 1 comment · May be fixed by #1238
Open

ZIO's WithRun#runContext fails with an error #1236

skelantros opened this issue Apr 11, 2024 · 1 comment · May be fixed by #1238

Comments

@skelantros
Copy link

The following code fails with java.lang.Error: Defect in zio.ZEnvironment: Could not find ErrorExample::Context inside ZEnvironment(Any -> Context(42))

import tofu.WithRun
import tofu.zioInstances.implicits.zioTofuWithRunImplicit
import zio._

object ZIOWithRunError extends ZIOAppDefault {
  case class Context(x: Int)

  val app: RIO[Context, Unit] = ZIO.service[Context].flatMap(Console.printLine(_))

  override def run: ZIO[Any with ZIOAppArgs with Scope, Any, Any] =
    WithRun[RIO[Context, *], Task, Context].runContext(app)(Context(42))
}

Based on the error message, it seems like Context's tag is not used to build ZEnvironment when using WithRun instance, resulting in ZIO being unable to find Context instance in the environment.

@skelantros
Copy link
Author

Fixed this locally, will submit a bit later.

@skelantros skelantros changed the title ZIO WithRun#runContext fails with an error ZIO's WithRun#runContext fails with an error Apr 11, 2024
@skelantros skelantros linked a pull request Apr 12, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant