arrow-kt / arrow-kt/arrow

Tracing reports a swallowed CancellationException warning

Open
#3,388 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
6.6k
Forks
472
Avg merge
3d 49m
Merged PRs (30d)
4

Description

I'm using Arrow 1.2.3.

I am writing a simple helper for Arrow Core that introduces a `Raise` context in which failures throw `AssertionError`, with the goal of using it to simplify writing tests. Since this helper would only be used in automated tests that are expected not to fail, enabling tracing by default seems reasonable as it helps understand the root cause, so the performance impact is worth it.

Using the following code:

```kotlin
@ExperimentalTraceApi
inline fun failOnRaise(block: Raise.() -> Success): Success {
val result = either {
traced(block) { trace, error ->
throw AssertionError("An operation raised $error\n${trace.stackTraceToString()}")
.apply {
for (suppressed in trace.suppressedExceptions())
addSuppressed(suppressed)
}
}
}

check(result is Either.Right) { "Impossible situation: we throw an error when the passed block raises, but it still gaves us a failed either: $result" }
return result.value
}

// In the test
failOnRaise {
raise(5)
}
```

I would expect this example to throw:
```
AssertionError: An operation raised `5`
arrow.core.raise.Traced: // some normal exception trace
```

But, instead, it throws:
```
java.lang.AssertionError: An operation raised 5
arrow.core.raise.Traced: kotlin.coroutines.cancellation.CancellationException should never get swallowed. Always re-throw it if captured.This swallows the exception of Arrow's Raise, and leads to unexpected behavior.When working with Arrow prefer Either.catch or arrow.core.raise.catch to automatically rethrow CancellationException.
at arrow.core.raise.DefaultRaise.raise(Fold.kt:270)
at opensavvy.prepared.compat.arrow.core.FailOnRaiseTest$1$3.invokeSuspend(FailOnRaiseTest.kt:21)
```

Is it indented that this is the error message generated by `traced`? If so, it's bit too worrying to be normal behavior. If not, is there something wrong on my end?

Contributor guide

Open the contributing guide

Research direction

Reproduce the report from opensavvy.prepared.compat.arrow.core.FailOnRaiseTest$1$3 at FailOnRaiseTest.kt:21, then inspect arrow.core.raise.DefaultRaise.raise in Fold.kt:270 and the traced call used by the example. Determine whether traced is producing the CancellationException warning and verify the behavior with the reported Arrow 1.2.3 scenario; done means the resulting trace or warning matches the intended behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
observability
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.