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

Missing stacktraces from right-side effect of .flatMap #8747

Open
kluen opened this issue Apr 15, 2024 · 3 comments
Open

Missing stacktraces from right-side effect of .flatMap #8747

kluen opened this issue Apr 15, 2024 · 3 comments

Comments

@kluen
Copy link
Contributor

kluen commented Apr 15, 2024

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.

@jdegoes
Copy link
Member

jdegoes commented May 8, 2024

/bounty $100

I would expect to see a and b in the stack trace of c.

Copy link

algora-pbc bot commented May 8, 2024

💎 $100 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #8747 with your implementation plan
  2. Submit work: Create a pull request including /claim #8747 in the PR body to claim the bounty
  3. 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 bountyShare on socials

@kyri-petrou
Copy link
Contributor

kyri-petrou commented May 9, 2024

@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 :

  1. Provide before/after benchmark results of the NarrowFlatMapBenchmark and BroadFlatMapBenchmark suites (at the very least) showing that the runloop performance wasn't affected, or
  2. Perhaps create a runtime flag (disabled by default?) to enable detailed stack traces

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

No branches or pull requests

3 participants