Skip to content

Commit 0efa558

Browse files
committed
Discard strict double-wrapping check
We decided not to go with it, as it may dump a lot of error messages to a clueless user's console.
1 parent 00cb4e5 commit 0efa558

File tree

2 files changed

+3
-22
lines changed

2 files changed

+3
-22
lines changed

IntelliJ-patches.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,7 @@ Some logic related to instrumentation was extracted to separate methods so that
7272

7373
- `kotlinx.coroutines.flow.internal.FlowValueWrapperInternal` -- wrapper class used to create a unique object for the debugger agent
7474
- `kotlinx.coroutines.flow.internal.FlowValueWrapperInternalKt.wrapInternal` -- returns passed argument by default; the agent instruments it to call `wrapInternalDebuggerCapture` instead
75-
- `kotlinx.coroutines.flow.internal.FlowValueWrapperInternalKt.wrapInternalDebuggerCaptureX` -- wraps passed arguments into a `FlowValueWrapperInternal`; only used after transformation.
76-
`X` may mean `Strict` or `Lenient`. Both methods handle double-wrapping, which is always an error that is hard to investigate if it arises naturally.
77-
- `Strict` throws an exception, thus allowing fail-fast strategy
78-
- `Lenient` returns its argument without wrapping it again
79-
Debugger agent decides which version to use based on IDE settings.
75+
- `kotlinx.coroutines.flow.internal.FlowValueWrapperInternalKt.wrapInternalDebuggerCapture` -- wraps passed arguments into a `FlowValueWrapperInternal`; only used after transformation.
8076
- `kotlinx.coroutines.flow.internal.FlowValueWrapperInternalKt.unwrapInternal` -- returns passed argument by default; the agent instruments it to call `unwrapInternalDebuggerCapture` instead
8177
- `kotlinx.coroutines.flow.internal.FlowValueWrapperInternalKt.unwrapInternalDebuggerCapture` -- unwraps passed argument so it returns the original value; only used after transformation
8278
- `kotlinx.coroutines.flow.internal.FlowValueWrapperInternalKt.emitInternal(FlowCollector, value)` -- common insertion point for a debugger agent; simplifies instrumentation; the value is always being unwrapped inside

kotlinx-coroutines-core/common/src/flow/internal/FlowValueWrapperInternal.kt

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,8 @@ internal class FlowValueWrapperInternal<T>(val value: T)
1515
internal fun <T> wrapInternal(value: T): T = value
1616
internal fun <T> unwrapInternal(value: T): T = value
1717

18-
// debugger agent transforms wrapInternal so it returns wrapInternalDebuggerCaptureX(value) instead of just value.
19-
// "X" may be Strict or Lenient, debugger agent picks one depending on its arguments.
20-
// Both versions are aimed at handling double wrapping, which is always an error;
21-
// a lenient version swallows it, allowing the application to proceed normally
22-
// at the cost of not working async stack traces in the place;
23-
// a strict version throws an exception so that the issue could be traced at its earliest point
24-
25-
private fun wrapInternalDebuggerCaptureStrict(value: Any?): Any {
26-
if (value is FlowValueWrapperInternal<*>) {
27-
throw DoubleWrappingException("Double-wrapping detected; failing fast. This should never happen!")
28-
}
29-
return FlowValueWrapperInternal(value)
30-
}
31-
32-
private fun wrapInternalDebuggerCaptureLenient(value: Any?): Any {
18+
// debugger agent transforms wrapInternal so it returns wrapInternalDebuggerCapture(value) instead of just value.
19+
private fun wrapInternalDebuggerCapture(value: Any?): Any {
3320
if (value is FlowValueWrapperInternal<*>) {
3421
return value
3522
}
@@ -50,5 +37,3 @@ private fun unwrapInternalDebuggerCapture(value: Any?): Any? {
5037
internal suspend fun <T> FlowCollector<T>.emitInternal(value: Any?) {
5138
emit(NULL.unbox(unwrapInternal(value)))
5239
}
53-
54-
private class DoubleWrappingException(message: String) : RuntimeException(message)

0 commit comments

Comments
 (0)