Missing stacktraces from right-side effect of `.flatMap`
When watching @adamw's recent talk where he compares the usability of direct-style approaches to plain ZIO, I was a bit surprised to see that he argued that ZIO's stacktraces are only "basic". In particular, I was surprised about ZIO's behaviour in this example.
I experimented a bit to understand the behaviour better and found that the stacktrace only contains the "frames" of the left-hand side of a flatMap. Here is an example to show the issue:
//> using scala 3.4
//> using dep dev.zio::zio:2.0.22
import zio.*
object PrintsStacktrace extends ZIOAppDefault:
def run = a
def a = b.flatMap(_ => ZIO.unit)
def b = c.flatMap(_ => ZIO.unit)
def c = ZIO.fail("The failure")
This prints:
timestamp=2024-04-15T09:50:00.275792Z level=ERROR thread=#zio-fiber-1 message="" cause="Exception in thread "zio-fiber-4" java.lang.String: The failure
at <empty>.PrintsStacktrace.c(PrintsStacktrace.scala:10)
at <empty>.PrintsStacktrace.b(PrintsStacktrace.scala:9)
at <empty>.PrintsStacktrace.a(PrintsStacktrace.scala:8)"
which includes the helpful info on where the effects where constructed.
Here is the example where we do not get helpful output:
//> using scala 3.4
//> using dep dev.zio::zio:2.0.22
import zio.*
object NoStacktrace extends ZIOAppDefault:
def run = a
def a = ZIO.unit.flatMap(_ => b)
def b = ZIO.unit.flatMap(_ => c)
def c = ZIO.fail("The failure")
which prints
timestamp=2024-04-15T09:51:59.317835Z level=ERROR thread=#zio-fiber-1 message="" cause="Exception in thread "zio-fiber-4" java.lang.String: The failure
at <empty>.NoStacktrace.c(NoStacktrace.scala:10)"
I am not sure if this behaviour is intentional, but I agree that this is not ideal from a usability standpoint, because we are missing valuable information to locate the failed effect.
/bounty $100
I would expect to see a and b in the stack trace of c.
đ $100 bounty âĸ ZIO
Steps to solve:
-
Start working: Comment
/attempt #8747with your implementation plan -
Submit work: Create a pull request including
/claim #8747in the PR body to claim the bounty - Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts
Thank you for contributing to zio/zio!
Add a bounty âĸ Share on socials
| Attempt | Started (GMT+0) | Solution |
|---|---|---|
| đĄ @itsdheerajdp | Sep 7, 2024, 7:14:46 AM | WIP |
@jdegoes just want to add a requirement to this ticket if possible?
Fixing this can negatively impact performance of the runloop depending on the implementation. I'm actually not sure if it's even possible to fix it without impacting performance to some degree.
I thin any attempted solution should either :
- Provide before/after benchmark results of the
NarrowFlatMapBenchmarkandBroadFlatMapBenchmarksuites (at the very least) showing that the runloop performance wasn't affected, or - Perhaps create a runtime flag (disabled by default?) to enable detailed stack traces
/attempt #8747
| Algora profile | Completed bounties | Tech | Active attempts | Options |
|---|---|---|---|---|
| @itsdheerajdp | 4 bounties from 2 projects | HTML, JavaScript, TypeScript & more |
īš9153 |
Cancel attempt |
@itsdheerajdp: Reminder that in 7 days the bounty will become up for grabs, so please submit a pull request before then đ