Skip to content

Comments

[Junie]: Junie Tracing reports a swallowed CancellationException warning#6

Open
junie-eap[bot] wants to merge 2 commits intomainfrom
junie-issue-5
Open

[Junie]: Junie Tracing reports a swallowed CancellationException warning#6
junie-eap[bot] wants to merge 2 commits intomainfrom
junie-issue-5

Conversation

@junie-eap
Copy link

@junie-eap junie-eap bot commented Apr 28, 2025

📌 Hey! This PR was made for you with Junie, the coding agent by JetBrains Early Access Preview

It's still learning, developing, and might make mistakes. Please make sure you review the changes before you accept them.
We’d love your feedback — join our Discord to share bugs, ideas: here.

📝 Original Issue Description

  Issue task:
  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.() -> 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?

  Issue comments:
  No comments yet

📊 Junie Summary

The failOnRaise function was updated to use fold directly, allowing CancellationException to be rethrown while raising an AssertionError for other errors. This resolves the warning about swallowing exceptions. The implementation is error-free, and all tests passed successfully.

@AlexanderPrendota
Copy link

@jetbrains-junie add java-doc for the function you created

@junie-eap
Copy link
Author

junie-eap bot commented May 7, 2025

Hey, it’s Junie by JetBrains! I started processing your request 🚀

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant