Support Firefox stack format

It doesn't include the exception type and message.
This commit is contained in:
Ilya Gorbunov
2020-03-20 06:27:15 +03:00
parent 641f1a55cb
commit 4cc9909a70
@@ -68,23 +68,26 @@ private class ExceptionTraceBuilder {
private fun Throwable.dumpSelfTrace(indent: String, qualifier: String): Boolean {
target.append(indent).append(qualifier)
val shortInfo = this.toString()
if (hasSeen(this)) {
target.append("[CIRCULAR REFERENCE, SEE ABOVE: ").append(this).append("]\n")
target.append("[CIRCULAR REFERENCE, SEE ABOVE: ").append(shortInfo).append("]\n")
return false
}
visited.asDynamic().push(this)
var stack = this.asDynamic().stack as String?
if (stack != null) {
val stackStart = stack.indexOf(shortInfo).let { if (it < 0) 0 else it + shortInfo.length }
if (stackStart == 0) target.append(shortInfo).append("\n")
if (topStack.isEmpty()) {
topStack = stack
topStackStart = this.toString().length
topStackStart = stackStart
} else {
stack = dropCommonFrames(stack, this.toString().length)
stack = dropCommonFrames(stack, stackStart)
}
if (indent.isNotEmpty()) {
// indent stack, but avoid indenting exception message lines
val messageLines = 1 + (message?.count { c -> c == '\n' } ?: 0)
val messageLines = if (stackStart == 0) 0 else 1 + shortInfo.count { c -> c == '\n' }
stack.lineSequence().forEachIndexed { index: Int, line: String ->
if (index >= messageLines) target.append(indent)
target.append(line).append("\n")
@@ -93,7 +96,7 @@ private class ExceptionTraceBuilder {
target.append(stack).append("\n")
}
} else {
target.append(this.toString()).append("\n")
target.append(shortInfo).append("\n")
}
val suppressed = suppressedExceptions