From 4f97f7e61414fcf451f40ee29cb223007f9160d2 Mon Sep 17 00:00:00 2001 From: Maxime Girardet Date: Tue, 23 Apr 2024 21:42:49 +0000 Subject: [PATCH] merge: Hide the scary Arrow warning about catching CancellationException See merge request opensavvy/groundwork/prepared!61 --- compat/compat-arrow/src/commonMain/kotlin/FailOnRaise.kt | 10 +++++++++- 1 file(s) changed, 9 insertion(s)(+), 1 deletion(s)(-) diff --git a/compat/compat-arrow/src/commonMain/kotlin/FailOnRaise.kt b/compat/compat-arrow/src/commonMain/kotlin/FailOnRaise.kt --- a/compat/compat-arrow/src/commonMain/kotlin/FailOnRaise.kt +++ b/compat/compat-arrow/src/commonMain/kotlin/FailOnRaise.kt @@ -25,7 +25,15 @@ inline fun failOnRaise(block: Raise.() -> Success): Success { val result = either { traced(block) { trace, failure -> - throw AssertionError("An operation raised $failure\n${trace.stackTraceToString()}") + var stackTrace = trace.stackTraceToString() + + // The trace starts with a big warning from Arrow about catching its internal exception. + // This is actually normal behavior of the Arrow library: https://github.com/arrow-kt/arrow/issues/3388 + // Since there is nothing to worry about for the user, we just hide it. + if (stackTrace.startsWith("arrow.core.raise.Traced: kotlin.coroutines.cancellation.CancellationException should never get swallowed.")) + stackTrace = stackTrace.replaceBefore("\n", "").replaceFirst("\n", "") + + throw AssertionError("An operation raised $failure.\n$stackTrace") .apply { for (suppressed in trace.suppressedExceptions()) addSuppressed(suppressed) -- tangled.sh