Search code examples
scalazio

Getting a spurious fibre trace with zip and for comprehension


I have just started to look at ZIO to try to improve my Scala. I have started by trying to update some of my old code. I have wrapped some legacy code which returns a configuration wrapped in an option and I'm converting that to a ZIO which I'm then using in for comprehension.

The code works as expected but if I return None I get:

Fiber failed.
A checked error was not handled.
None

Fiber:Id(1612612180323,1) was supposed to continue to:
  a future continuation at tryzio.MyApp$.run(MyApp.scala:94)
  a future continuation at zio.ZIO.exitCode(ZIO.scala:543)

Fiber:Id(1612612180323,1) execution trace:
  at zio.ZIO$.fromOption(ZIO.scala:3246)
  at tryzio.MyApp$.run(MyApp.scala:93)

The code works as expected for both a Some and a None, but I get the spurious Fibre messages for a None.

The code that generates this is really very simple:

def run(args: List[String]) = ({

for {
  cmdln <- ZIO.fromOption(getConfig(args.toArray))
  _ <- putStrLn("Model Data Builder")
  _ <- putStrLn(s"\nVerbose: ${cmdln.verbose}")
  } yield()


}).exitCode

But I have clearly missed something obvious! I'm new to ZIO so please use small words when explains my lack of understanding. Do I need to join all Fibres? I have tried to catch the None and then exit but actually my code never strops running if I do that - Very strange.


Solution

  • .exitCode caught an error (empty configuration) which hasn't been handled in the code, printed debug information in stdErr and exited the program with status 1. So it works as expected.

    I agree that the error message is a bit misleading and should start with something something business-related rather than fiber failed. You might fire a ticket on github.