Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Full stack trace lost when using retry #7586

@hindog

Description

@hindog

Description

When using retry, the stack trace for the cause of the failure is lost when the retries are exhausted.

Example

import zio._

case object StackExample extends ZIOAppDefault {
  override def run = {
    val effect = (for {
      _ <- ZIO.logInfo("Running attempt...")
      _ <- foo()
    } yield ())

    effect.tapErrorCause(ZIO.logErrorCause(_)) orElse // preserves stack trace
      effect.retry(Schedule.recurs(1)) // stack trace truncated at location of 'retry'
  }

  def foo(): Task[Unit] = ZIO.fail(new Exception("Triggered exception!"))
}

Outputs:

timestamp=2022-12-01T18:52:22.388872Z level=INFO thread=#zio-fiber-4 message="Running attempt..." location=whoco.sourcing.scripts.examples.StackExample.run.effect file=StackExample.scala line=9
timestamp=2022-12-01T18:52:22.403133Z level=ERROR thread=#zio-fiber-4 message="" cause="Exception in thread "zio-fiber-4" java.lang.Exception: java.lang.Exception: Triggered exception!
	at whoco.sourcing.scripts.examples.StackExample.foo(StackExample.scala:17)
	at whoco.sourcing.scripts.examples.StackExample.run.effect(StackExample.scala:10)
	at whoco.sourcing.scripts.examples.StackExample.run(StackExample.scala:13)" location=whoco.sourcing.scripts.examples.StackExample.run file=StackExample.scala line=13
timestamp=2022-12-01T18:52:22.423265Z level=INFO thread=#zio-fiber-4 message="Running attempt..." location=whoco.sourcing.scripts.examples.StackExample.run.effect file=StackExample.scala line=9
timestamp=2022-12-01T18:52:22.493438Z level=INFO thread=#zio-fiber-4 message="Running attempt..." location=whoco.sourcing.scripts.examples.StackExample.run.effect file=StackExample.scala line=9
timestamp=2022-12-01T18:52:22.500563Z level=ERROR thread=#zio-fiber-0 message="" cause="Exception in thread "zio-fiber-4" java.lang.Exception: java.lang.Exception: Triggered exception!
	at whoco.sourcing.scripts.examples.StackExample.run(StackExample.scala:14)"

Expected Behavior

In the example above, I was expecting that the effect.retry(Schedule.recurs(1)) would have a stack trace similar to effect. Eg, something like this:

	at whoco.sourcing.scripts.examples.StackExample.foo(StackExample.scala:17)
	at whoco.sourcing.scripts.examples.StackExample.run.effect(StackExample.scala:10)
	at whoco.sourcing.scripts.examples.StackExample.run(StackExample.scala:14)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions