From 0ac1df3d02d5f567e5432f171225a0b085d7295b Mon Sep 17 00:00:00 2001 From: "junie-eap[bot]" Date: Mon, 28 Apr 2025 11:45:53 +0000 Subject: [PATCH 1/2] chore(junie): Junie Tracing reports a swallowed CancellationException warning changes from the task: #5 --- fixed_code.kt | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 fixed_code.kt diff --git a/fixed_code.kt b/fixed_code.kt new file mode 100644 index 00000000000..9b4f771bf99 --- /dev/null +++ b/fixed_code.kt @@ -0,0 +1,32 @@ +import arrow.core.Either +import arrow.core.raise.ExperimentalTraceApi +import arrow.core.raise.Raise +import arrow.core.raise.fold +import arrow.core.raise.traced +import kotlin.coroutines.cancellation.CancellationException + +@ExperimentalTraceApi +inline fun failOnRaise(block: Raise.() -> Success): Success { + // Instead of using either, which catches and wraps CancellationException, + // we'll use fold directly with a custom handler that rethrows CancellationException + return fold( + block = { + traced(block) { trace, error -> + throw AssertionError("An operation raised $error\n${trace.stackTraceToString()}") + .apply { + for (suppressed in trace.suppressedExceptions()) + addSuppressed(suppressed) + } + } + }, + catch = { throwable -> + // Rethrow CancellationException to avoid the warning + if (throwable is CancellationException) throw throwable + throw throwable // Rethrow other exceptions as well + }, + recover = { error -> + throw AssertionError("Impossible situation: recover was called with $error") + }, + transform = { value -> value } + ) +} From e662baf196d9391b120ac837c45a93f42dcef6c0 Mon Sep 17 00:00:00 2001 From: "junie-eap[bot]" Date: Wed, 7 May 2025 09:36:58 +0000 Subject: [PATCH 2/2] [6] Improvement from Junie summary: JavaDoc was successfully added to the function, clearly explaining its purpose, parameters, return value, and exceptions. The implementation is error-free, and all tests passed. --- fixed_code.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fixed_code.kt b/fixed_code.kt index 9b4f771bf99..156bf789360 100644 --- a/fixed_code.kt +++ b/fixed_code.kt @@ -5,6 +5,20 @@ import arrow.core.raise.fold import arrow.core.raise.traced import kotlin.coroutines.cancellation.CancellationException +/** + * A helper function for Arrow Core that simplifies writing tests by creating a Raise context + * where failures throw AssertionError instead of returning an Either. + * + * This function properly handles CancellationException by rethrowing it directly instead of + * swallowing it, which avoids the warning from Arrow's tracing system. + * + * @param block The code block to execute within the Raise context + * @param Failure The type of failure that can be raised + * @param Success The return type of the block + * @return The successful result of the block execution + * @throws AssertionError If the block raises a failure, with the failure value and trace information + * @throws CancellationException If a CancellationException occurs during execution + */ @ExperimentalTraceApi inline fun failOnRaise(block: Raise.() -> Success): Success { // Instead of using either, which catches and wraps CancellationException,