zio/interop-reactive-streams

Stack traces are lost when using `publisher.toZIOStream()`

hindog opened this issue · 2 comments

Given this example:

import org.reactivestreams._
import zio.interop.reactivestreams._
import zio._

object ReactiveTest extends ZIOAppDefault {
  
  class TestPublisher extends Publisher[Int] {
    override def subscribe(s: Subscriber[_ >: RuntimeFlags]): Unit = {
      s.onSubscribe(new Subscription {
        override def request(n: Long): Unit = {
          println("publishing 1")
          s.onNext(1)
          println("publishing error")
          s.onError(new Exception("Some Error!"))
        }
        override def cancel(): Unit = println("cancelled")
      })
    }
  }

  override def run = {
    val publisher = new TestPublisher()

    sumValues(publisher).tapErrorCause { cause =>
      println("STACK TRACE: " + cause.trace.prettyPrint)
      ZIO.unit
    }
  }

  def sumValues(publisher: Publisher[Int]): Task[Long] = {
    publisher.toZIOStream().runCount
  }
}

The output is:

publishing 1
publishing error
cancelled
STACK TRACE: 
timestamp=2022-09-14T20:01:34.266895Z level=ERROR thread=#zio-fiber-0 message="" cause="Exception in thread "zio-fiber-" java.lang.Exception: java.lang.Exception: Some Error!
"

Note that that no stack trace lines are printed after STACK TRACE:

Is this expected behavior?

Thanks for reporting. This still worked as expected on RC6 (see below), but I can confirm it's broken in the latest version. I'll investigate.

publishing 1
publishing error
cancelled
STACK TRACE: StackTrace(Runtime(6,1665932683,),Chunk(zio.interop.reactivestreams.ReactiveTest.sumValues(ReactiveTest.scala:32),zio.interop.reactivestreams.ReactiveTest.run(ReactiveTest.scala:25)))
timestamp=2022-10-16T15:04:43.470822Z level=ERROR thread=#zio-fiber-0 message="" cause="Exception in thread "zio-fiber-6" java.lang.Exception: java.lang.Exception: Some Error!
	at zio.interop.reactivestreams.ReactiveTest.sumValues(ReactiveTest.scala:32)
	at zio.interop.reactivestreams.ReactiveTest.run(ReactiveTest.scala:25)"

The change of behavior is in ZStream, not in the interop:

  def sumValues(publisher: Publisher[Int]) =
    (ZStream(1, 2, 3) ++ ZStream.fail(new Exception("boom"))).runSum

results in

STACK TRACE: Exception in thread "zio-fiber-" java.lang.Exception: java.lang.Exception: boom

timestamp=2022-10-16T15:54:17.876940Z level=ERROR thread=#zio-fiber-0 message="" cause="Exception in thread "zio-fiber-" java.lang.Exception: java.lang.Exception: boom
"

as well.

If you feel like this is a bug, please file a bug in ZIO streams.