-
Notifications
You must be signed in to change notification settings - Fork 458
Open
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:
@ExperimentalTraceApi
inline fun <Failure, Success> failOnRaise(block: Raise<Failure>.() -> 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?
Metadata
Metadata
Assignees
Labels
No labels