cleanStackTraceInternal now cleans the stack track from all coroutine info for all dorkbox.network stack traces.
This commit is contained in:
parent
533aec6c2d
commit
113de5d12e
|
@ -96,7 +96,7 @@ internal class ListenerManager<CONNECTION: Connection>(private val logger: KLogg
|
|||
}
|
||||
|
||||
/**
|
||||
* Remove from the stacktrace (going in reverse), kotlin coroutine info ONLY. This is for internal logs when a problem happens INSIDE the network stack
|
||||
* Remove from the stacktrace kotlin coroutine info ONLY that is inside the network stack. This is for internal logs when a problem happens INSIDE the network stack.
|
||||
*
|
||||
* Neither of these are useful in resolving exception handling from a users perspective, and only clutter the stacktrace.
|
||||
*/
|
||||
|
@ -109,29 +109,18 @@ internal class ListenerManager<CONNECTION: Connection>(private val logger: KLogg
|
|||
return
|
||||
}
|
||||
|
||||
var newEndIndex = size - 1 // offset by 1 because we have to adjust for the access index
|
||||
|
||||
for (i in newEndIndex downTo 0) {
|
||||
val stackName = stackTrace[i].className
|
||||
if (i == newEndIndex) {
|
||||
if (stackName.startsWith("kotlinx.coroutines.") ||
|
||||
stackName.startsWith("kotlin.coroutines.")) {
|
||||
newEndIndex--
|
||||
} else {
|
||||
break
|
||||
}
|
||||
// we want to ONLY filter stuff that is past the highest dorkbox index AND is a coroutine.
|
||||
val firstDorkboxIndex = stackTrace.indexOfFirst { it.className.startsWith("dorkbox.network.") }
|
||||
val lastDorkboxIndex = stackTrace.indexOfLast { it.className.startsWith("dorkbox.network.") }
|
||||
throwable.stackTrace = stackTrace.filterIndexed { index, element ->
|
||||
val stackName = element.className
|
||||
if (index <= firstDorkboxIndex && index >= lastDorkboxIndex) {
|
||||
true
|
||||
} else {
|
||||
!(stackName.startsWith("kotlinx.coroutines.") ||
|
||||
stackName.startsWith("kotlin.coroutines."))
|
||||
}
|
||||
}
|
||||
|
||||
newEndIndex++ // have to add 1 back, because a copy must be by size (and we access from 0)
|
||||
|
||||
if (newEndIndex > 0) {
|
||||
// newEndIndex will also remove the VERY LAST CachedMethod or CachedAsmMethod access invocation (because it's offset by 1)
|
||||
throwable.stackTrace = stackTrace.copyOfRange(0, newEndIndex)
|
||||
} else {
|
||||
// keep just one, since it's a stack frame INSIDE our network library, and we need that!
|
||||
throwable.stackTrace = stackTrace.copyOfRange(0, 1)
|
||||
}
|
||||
}.toTypedArray()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -186,10 +186,13 @@ internal class ClientHandshake<CONNECTION: Connection>(
|
|||
ListenerManager.cleanStackTraceInternal(failedEx)
|
||||
throw failedEx
|
||||
}
|
||||
|
||||
if (connectionHelloInfo == null) {
|
||||
// no longer necessary to hold this connection open (if not a failure, we close the handshake after the DONE message)
|
||||
handshakeConnection.close()
|
||||
throw ClientTimedOutException("Waiting for registration response from server")
|
||||
val exception = ClientTimedOutException("Waiting for registration response from server")
|
||||
ListenerManager.cleanStackTraceInternal(exception)
|
||||
throw exception
|
||||
}
|
||||
|
||||
return connectionHelloInfo!!
|
||||
|
@ -203,7 +206,6 @@ internal class ClientHandshake<CONNECTION: Connection>(
|
|||
try {
|
||||
endPoint.writeHandshakeMessage(handshakeConnection.publication, registrationMessage)
|
||||
} catch (e: Exception) {
|
||||
logger.error("Handshake error!", e)
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -247,7 +249,9 @@ internal class ClientHandshake<CONNECTION: Connection>(
|
|||
}
|
||||
|
||||
if (!connectionDone) {
|
||||
throw ClientTimedOutException("Waiting for registration response from server")
|
||||
val exception = ClientTimedOutException("Waiting for registration response from server")
|
||||
ListenerManager.cleanStackTraceInternal(exception)
|
||||
throw exception
|
||||
}
|
||||
|
||||
return connectionDone
|
||||
|
|
Loading…
Reference in New Issue
Block a user