-
Notifications
You must be signed in to change notification settings - Fork 438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracing POC #2946
Merged
Merged
Tracing POC #2946
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d04a400
Add tracing
nomisRev 3b108cd
Update API files
nomisRev 209248f
Retrigger CI
nomisRev 04d0616
Add couple tests, and support nesting tracing calls
nomisRev aeaabe2
Merge remote-tracking branch 'origin/main' into sv-tracing
nomisRev a75658f
Make fix after merge, and revert delegation in ior builder
nomisRev efd6fc8
Move trace comparison test to JVM only
nomisRev 2766fcc
Fix test
nomisRev 4d22cf1
Test review suggestions
nomisRev 9693f1b
Revert "Test review suggestions"
nomisRev b2f01e7
Hide exceptions from public API, and turn traced into 2 param method
nomisRev e3bb2d8
Apply suggestions from code review
nomisRev efc2434
Merge branch 'main' into sv-tracing
nomisRev e58cdb3
Fix compilation errors
franciscodr b107947
Update arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/ra…
nomisRev f6bc835
Update arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/ra…
nomisRev 1594d47
Update API files
nomisRev ee8e7af
Update arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/ra…
nomisRev 9208d8c
Add import @JvmInline
nomisRev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Trace.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
@file:JvmMultifileClass | ||
@file:JvmName("RaiseKt") | ||
package arrow.core.raise | ||
|
||
import kotlin.coroutines.cancellation.CancellationException | ||
import kotlin.jvm.JvmMultifileClass | ||
import kotlin.jvm.JvmName | ||
|
||
@RequiresOptIn("This API is experimental, and may change in the future.") | ||
public annotation class ExperimentalTraceApi | ||
|
||
/** Tracing result of `R`. Allows to inspect `R`, and the traces from where it was raised. */ | ||
nomisRev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@ExperimentalTraceApi | ||
public class Trace(private val exception: CancellationException) { | ||
nomisRev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
* Returns the stacktrace as a [String] | ||
* | ||
* Note, the first line in the stacktrace will be the `RaiseCancellationException`. | ||
* The users call to `raise` can found in the_second line of the stacktrace. | ||
*/ | ||
public fun stackTraceToString(): String = exception.stackTraceToString() | ||
|
||
/** | ||
* Prints the stacktrace. | ||
* | ||
* Note, the first line in the stacktrace will be the `RaiseCancellationException`. | ||
* The users call to `raise` can found in the_second line of the stacktrace. | ||
*/ | ||
public fun printStackTrace(): Unit = | ||
exception.printStackTrace() | ||
|
||
/** | ||
* Returns the suppressed exceptions that occurred during cancellation of the surrounding coroutines, | ||
* | ||
* For example when working with `Resource`, or `bracket`: | ||
* When consuming a `Resource` fails due to [Raise.raise] it results in `ExitCase.Cancelled`, | ||
* if the finalizer then results in a `Throwable` it will be added as a `suppressedException` to the [CancellationException]. | ||
*/ | ||
public fun suppressedExceptions(): List<Throwable> = | ||
exception.suppressedExceptions | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/TraceSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package arrow.core.raise | ||
|
||
import arrow.core.right | ||
import io.kotest.assertions.throwables.shouldThrow | ||
import io.kotest.core.spec.style.StringSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.property.Arb | ||
import io.kotest.property.arbitrary.int | ||
import io.kotest.property.arbitrary.string | ||
import io.kotest.property.checkAll | ||
import kotlinx.coroutines.CompletableDeferred | ||
|
||
@OptIn(ExperimentalTraceApi::class) | ||
class TraceSpec : StringSpec({ | ||
"trace is empty when no errors" { | ||
checkAll(Arb.int()) { i -> | ||
either<Nothing, Int> { | ||
traced({ i }) { _,_ -> unreachable() } | ||
} shouldBe i.right() | ||
} | ||
} | ||
|
||
"trace is empty with exception" { | ||
checkAll(Arb.string()) { msg -> | ||
val error = RuntimeException(msg) | ||
shouldThrow<RuntimeException> { | ||
either<Nothing, Int> { | ||
traced({ throw error }) { _,_ -> unreachable() } | ||
} | ||
}.message shouldBe msg | ||
} | ||
} | ||
|
||
"nested tracing - identity" { | ||
val inner = CompletableDeferred<String>() | ||
ior(String::plus) { | ||
traced({ | ||
traced({ raise("") }) { traced, _ -> | ||
inner.complete(traced.stackTraceToString()) | ||
} | ||
}) { traced, _ -> | ||
inner.await() shouldBe traced.stackTraceToString() | ||
} | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change introduces a compilation error because
raise
andraised
properties don't exist inCancellationException
. Those properties belong toRaiseCancellationExceptionNoTrace
andRaiseCancellationException
, so we need the smart cast here.