@@ -12,9 +12,7 @@ import kotlin.coroutines.*
12
12
import kotlin.coroutines.intrinsics.*
13
13
14
14
internal actual fun <E : Throwable > recoverStackTrace (exception : E ): E {
15
- if (recoveryDisabled(exception)) {
16
- return exception
17
- }
15
+ if (recoveryDisabled(exception)) return exception
18
16
// No unwrapping on continuation-less path: exception is not reported multiple times via slow paths
19
17
val copy = tryCopyException(exception) ? : return exception
20
18
return copy.sanitizeStackTrace()
@@ -41,10 +39,7 @@ private fun <E : Throwable> E.sanitizeStackTrace(): E {
41
39
}
42
40
43
41
internal actual fun <E : Throwable > recoverStackTrace (exception : E , continuation : Continuation <* >): E {
44
- if (recoveryDisabled(exception) || continuation !is CoroutineStackFrame ) {
45
- return exception
46
- }
47
-
42
+ if (recoveryDisabled(exception) || continuation !is CoroutineStackFrame ) return exception
48
43
return recoverFromStackFrame(exception, continuation)
49
44
}
50
45
@@ -146,26 +141,23 @@ internal actual suspend inline fun recoverAndThrow(exception: Throwable): Nothin
146
141
}
147
142
148
143
internal actual fun <E : Throwable > unwrap (exception : E ): E {
149
- if (recoveryDisabled(exception)) {
150
- return exception
151
- }
152
-
144
+ if (recoveryDisabled(exception)) return exception
153
145
val cause = exception.cause
154
146
// Fast-path to avoid array cloning
155
147
if (cause == null || cause.javaClass != exception.javaClass) {
156
148
return exception
157
149
}
158
-
150
+ // Slow path looks for artificial frames in a stack-trace
159
151
if (exception.stackTrace.any { it.isArtificial() }) {
160
152
@Suppress(" UNCHECKED_CAST" )
161
- return exception. cause as ? E ? : exception
153
+ return cause as E
162
154
} else {
163
155
return exception
164
156
}
165
157
}
166
158
167
159
private fun <E : Throwable > recoveryDisabled (exception : E ) =
168
- ! RECOVER_STACKTRACES || ! DEBUG || exception is NonRecoverableThrowable
160
+ ! RECOVER_STACK_TRACES || exception is NonRecoverableThrowable
169
161
170
162
private fun createStackTrace (continuation : CoroutineStackFrame ): ArrayDeque <StackTraceElement > {
171
163
val stack = ArrayDeque <StackTraceElement >()
0 commit comments