IJPL-158517 ensure dumpCoroutines never throws

GitOrigin-RevId: e6217b2c4aa6c4ec1ec7f5f101a2d02e32356cce
This commit is contained in:
Vadim Salavatov
2024-07-29 12:50:40 +02:00
committed by intellij-monorepo-bot
parent 6e41cff151
commit d6190127db

View File

@@ -48,16 +48,24 @@ fun enableCoroutineDump(): Result<Unit> {
*/
//@JvmOverloads
fun dumpCoroutines(scope: CoroutineScope? = null, stripDump: Boolean = true, deduplicateTrees: Boolean = true): String? {
if (!isCoroutineDumpEnabled()) {
return null
try {
if (!isCoroutineDumpEnabled()) {
return null
}
val charset = StandardCharsets.UTF_8.name()
val outputStream = ByteArrayOutputStream()
PrintStream(BufferedOutputStream(outputStream), true, charset).use { out ->
val jobTree = jobTrees(scope).toList()
dumpCoroutines(jobTree, out, stripDump, deduplicateTrees)
}
return outputStream.toString(charset)
} catch (e: Throwable) {
// if there is an unexpected exception, we won't be able to provide meaningful information anyway,
// but the exception should not prevent other diagnostic tools from collecting data
return "Coroutine dump has failed: ${e.message}\n" +
"Please report this issue to the developers.\n" +
e.stackTraceToString()
}
val charset = StandardCharsets.UTF_8.name()
val outputStream = ByteArrayOutputStream()
PrintStream(BufferedOutputStream(outputStream), true, charset).use { out ->
val jobTree = jobTrees(scope).toList()
dumpCoroutines(jobTree, out, stripDump, deduplicateTrees)
}
return outputStream.toString(charset)
}
/**