I ran the code for chapter 4 and got a different output than you suggested should appear for the cases where Friend.requestBread would fail. I got the "Attempt X:..." messages but wouldn't get the Failure(Friend Unreachable). Instead I would get a stack trace that looked like this:
timestamp=2026-07-23T16:13:17.652150800Z level=ERROR thread=#zio-fiber-644678636 message="" cause="Exception in thread "zio-fiber-1699620585" java.lang.String: Failure(Friend Unreachable)
at Chapter04_Initialization.Friend.forcedFailure(Chapter04_Initialization.scala:257)
at Chapter04_Initialization.Friend.requestBread(Chapter04_Initialization.scala:275)
...
I spent quite a bit of time with Gemini trying a lot of different things to solve the problem but finally got it working by updating the ZIOAppDebug like this:
override def run: ZIO[ZIOAppArgs & Scope, Any, Any] =
// this tries to create consistency for how we run and print output between the book and the examples
ZIO.scoped:
self.run
// Added the catch handler.
.catchAll:
case err: String =>
ZIO.debug(s"$err")
case other =>
ZIO.fail(other)
.tapSome:
case result if !result.isInstanceOf[Unit] =>
Console.printLine:
s"Result: $result"
I ran the code for chapter 4 and got a different output than you suggested should appear for the cases where Friend.requestBread would fail. I got the "Attempt X:..." messages but wouldn't get the Failure(Friend Unreachable). Instead I would get a stack trace that looked like this:
I spent quite a bit of time with Gemini trying a lot of different things to solve the problem but finally got it working by updating the ZIOAppDebug like this: