@@ -12,9 +12,7 @@ import kotlin.coroutines.*
1212import kotlin.coroutines.intrinsics.*
1313
1414internal actual fun <E : Throwable > recoverStackTrace (exception : E ): E {
15- if (recoveryDisabled(exception)) {
16- return exception
17- }
15+ if (recoveryDisabled(exception)) return exception
1816 // No unwrapping on continuation-less path: exception is not reported multiple times via slow paths
1917 val copy = tryCopyException(exception) ? : return exception
2018 return copy.sanitizeStackTrace()
@@ -41,10 +39,7 @@ private fun <E : Throwable> E.sanitizeStackTrace(): E {
4139}
4240
4341internal 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
4843 return recoverFromStackFrame(exception, continuation)
4944}
5045
@@ -146,26 +141,23 @@ internal actual suspend inline fun recoverAndThrow(exception: Throwable): Nothin
146141}
147142
148143internal actual fun <E : Throwable > unwrap (exception : E ): E {
149- if (recoveryDisabled(exception)) {
150- return exception
151- }
152-
144+ if (recoveryDisabled(exception)) return exception
153145 val cause = exception.cause
154146 // Fast-path to avoid array cloning
155147 if (cause == null || cause.javaClass != exception.javaClass) {
156148 return exception
157149 }
158-
150+ // Slow path looks for artificial frames in a stack-trace
159151 if (exception.stackTrace.any { it.isArtificial() }) {
160152 @Suppress(" UNCHECKED_CAST" )
161- return exception. cause as ? E ? : exception
153+ return cause as E
162154 } else {
163155 return exception
164156 }
165157}
166158
167159private fun <E : Throwable > recoveryDisabled (exception : E ) =
168- ! RECOVER_STACKTRACES || ! DEBUG || exception is NonRecoverableThrowable
160+ ! RECOVER_STACK_TRACES || exception is NonRecoverableThrowable
169161
170162private fun createStackTrace (continuation : CoroutineStackFrame ): ArrayDeque <StackTraceElement > {
171163 val stack = ArrayDeque <StackTraceElement >()
0 commit comments