From 43538aaa4c9020df5ab2156f7566fd263421c3fc Mon Sep 17 00:00:00 2001 From: "junie-eap[bot]" Date: Wed, 7 May 2025 09:20:03 +0000 Subject: [PATCH] chore(junie): Tracing reports a swallowed CancellationException warning changes from the task: #8 --- fixed-failOnRaise.kt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 fixed-failOnRaise.kt diff --git a/fixed-failOnRaise.kt b/fixed-failOnRaise.kt new file mode 100644 index 00000000000..440979bc372 --- /dev/null +++ b/fixed-failOnRaise.kt @@ -0,0 +1,20 @@ +@ExperimentalTraceApi +inline fun failOnRaise(block: Raise.() -> Success): Success { + val result = either { + catch({ + traced(block) { trace, error -> + throw AssertionError("An operation raised $error\n${trace.stackTraceToString()}").apply { + for (suppressed in trace.suppressedExceptions()) + addSuppressed(suppressed) + } + } + }) { throwable -> + // Rethrow CancellationException and other fatal exceptions + throw throwable.nonFatalOrThrow() + } + } + check(result is Either.Right) { + "Impossible situation: we throw an error when the passed block raises, but it still gave us a failed either: $result" + } + return result.value +}