Satyam Agarwal
03/31/2021, 5:57 PMv0.13.0
private fun methodThatThrows(): Either<Throwable, Unit> = Either.catch { throw CancellationException("") }
@Test
fun `test parTraverse`(): Unit = runBlocking {
val result: Either<Throwable, Unit> = either {
(1..20).parTraverse { methodThatThrows().bind() }
}
result shouldBe CancellationException("").left()
}
I cannot reach assertion, and throws as soon as methodThatThrows
is called.
cc: @simon.vergauwen (Sorry for tagging you on easter vacation, just want to make you aware 🙂 )Satyam Agarwal
03/31/2021, 6:00 PMjava.util.concurrent.CancellationException:
at SomeTest.methodThatThrows(SomeTest.kt:12)
at SomeTest.access$methodThatThrows(SomeTest.kt:10)
at SomeTest$test parTraverse$1$invokeSuspend$$inlined$invoke$1$lambda$1.invokeSuspend(SomeTest.kt:17)
at SomeTest$test parTraverse$1$invokeSuspend$$inlined$invoke$1$lambda$1.invoke(SomeTest.kt)
at arrow.fx.coroutines.ParTraverse__ParTraverseKt$parTraverse$3$invokeSuspend$$inlined$map$lambda$1.invokeSuspend(ParTraverse.kt:180)
at |b|b|b(Coroutine boundary.|b(|b)
at kotlinx.coroutines.AwaitKt.awaitAll(Await.kt:42)
at arrow.fx.coroutines.ParTraverse__ParTraverseKt$parTraverse$3.invokeSuspend(ParTraverse.kt:183)
at SomeTest$test parTraverse$1$invokeSuspend$$inlined$invoke$1.invokeSuspend(SomeTest.kt:26)
Caused by: java.util.concurrent.CancellationException:
at SomeTest.methodThatThrows(SomeTest.kt:12)
at SomeTest.access$methodThatThrows(SomeTest.kt:10)
at SomeTest$test parTraverse$1$invokeSuspend$$inlined$invoke$1$lambda$1.invokeSuspend(SomeTest.kt:17)
at SomeTest$test parTraverse$1$invokeSuspend$$inlined$invoke$1$lambda$1.invoke(SomeTest.kt)
at arrow.fx.coroutines.ParTraverse__ParTraverseKt$parTraverse$3$invokeSuspend$$inlined$map$lambda$1.invokeSuspend(ParTraverse.kt:180)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
Jannis
03/31/2021, 6:03 PMEither,catch
See https://github.com/arrow-kt/arrow/blob/master/arrow-libs/core/arrow-core/src/main/kotlin/arrow/core/Either.kt#L985
And https://github.com/arrow-kt/arrow/blob/master/arrow-libs/core/arrow-core/src/main/kotlin/arrow/core/NonFatal.kt#L46Jannis
03/31/2021, 6:04 PMSatyam Agarwal
03/31/2021, 6:04 PMv0.11.0
for this ? This used to pass in the v0.11.0
Satyam Agarwal
03/31/2021, 6:06 PMSatyam Agarwal
03/31/2021, 6:07 PMSatyam Agarwal
03/31/2021, 6:08 PMJannis
03/31/2021, 6:10 PMEither.catch
if at all. Tho I can see the argument that it does the right thing in most cases and prevents common mistakes as catching fatal exceptions is usually a bad thing unless treated explicitly.Satyam Agarwal
03/31/2021, 6:11 PMsimon.vergauwen
03/31/2021, 7:14 PMMy guess is that since cancellation exceptions are meant for control flow catching them could lead to all sorts of weird behavior inside suspend functions.This is the rationale behind it. Kotlin has made
CancellationException
the official way of canceling a Coroutine
. If we'd catch it inside Either.catch
it would lead to all sorts of weird behavior and hard to debug bugs since debugging cancellation can be very painful.
Oh, has the implementation changed sinceÂThis has indeed changed since for this ? This used to pass in theÂv0.11.0
v0.11.0
0.11.0
since at that point in time CancellationException
was not the official way to cancel a Coroutine
yet.
Here is a link to CancellationException
as it's currently defined in the Kotlin Standard Libary. https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines.cancellation/-cancellation-exception/simon.vergauwen
03/31/2021, 7:15 PMCancellationException
?
Also if you have test that test Arrow, maybe it'd be interessting to add them to Arrow itself. Increasing our coverage is one of our next steps towards 1.0.0 and we could absolutely use the help 😉 I'd be happy to explain and help with anything you need along the way.simon.vergauwen
03/31/2021, 7:19 PMSatyam Agarwal
04/01/2021, 9:39 AMSatyam Agarwal
04/01/2021, 9:40 AM