inline fun <Error, A> Raise<Error>.traced(block: Raise<Error>.() -> A, trace: (trace: Trace, error: Error) -> Unit): A(source)

Inspect a Trace value of Error.

Tracing Error can be useful to know where certain errors, or failures are coming from. Let's say you have a DomainError, but it might be raised from many places in the project.

You would have to manually trace where this error is coming from, instead Trace offers you ways to inspect the actual stacktrace of where the raised value occurred.

Beware that tracing can only track the Raise.bind or Raise.raise call that resulted in the Error value, and not any location of where the Error, or Either.Left value was created.

public fun main() {
val error = effect<String, Int> { raise("error") }
error.traced { (trace, _: String) -> trace.printStackTrace() }
.fold({ require(it == "error") }, { error("impossible") })
arrow.core.continuations.RaiseCancellationException: Raised Continuation
at arrow.core.continuations.DefaultRaise.raise(Fold.kt:77)
at MainKtKt$main$error$1.invoke(MainKt.kt:6)
at MainKtKt$main$error$1.invoke(MainKt.kt:6)
at arrow.core.continuations.Raise$DefaultImpls.bind(Raise.kt:22)
at arrow.core.continuations.DefaultRaise.bind(Fold.kt:74)
at arrow.core.continuations.Effect__TracingKt$traced$2.invoke(Traced.kt:46)
at arrow.core.continuations.Effect__TracingKt$traced$2.invoke(Traced.kt:46)
at arrow.core.continuations.Effect__FoldKt.fold(Fold.kt:92)
at arrow.core.continuations.Effect.fold(Unknown Source)
at MainKtKt.main(MainKt.kt:8)
at MainKtKt.main(MainKt.kt)

NOTE: This implies a performance penalty of creating a stacktrace when calling Raise.raise, but this only occurs when composing traced. The stacktrace creation is disabled if no traced calls are made within the function composition.