forked from corda/corda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EG-65 - Improved error reporting on stdout (corda#5962)
I modified the `ErrorCodeRewritePolicy` to concatenate all the error messages of the exception's cause chain. The code will start from the throwable being passed to the logger and concatenate its error message with the one in its cause and proceed recursively until it finds an exception with no cause or it detects a loop (an exception already encountered in the traversal). This should provide customers with more information about errors without having to look at the logs (that should still remain the primary source of information)
- Loading branch information
Showing
2 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
common/logging/src/test/kotlin/net/corda/commmon/logging/WalkExceptionCausedByListTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package net.corda.commmon.logging | ||
|
||
import net.corda.common.logging.walkExceptionCausedByList | ||
import org.junit.Assert | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.Parameterized | ||
|
||
@RunWith(Parameterized::class) | ||
class WalkExceptionCausedByListTest(@Suppress("UNUSED_PARAMETER") testTitle: String, private val e: Throwable, private val expectedExceptionSequence: List<Throwable>) { | ||
|
||
private class TestThrowable(val id : Int, cause : Throwable?) : Throwable(cause) { | ||
override fun toString(): String { | ||
return "${this.javaClass.simpleName}(${this.id})" | ||
} | ||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
@Parameterized.Parameters(name = "{0}") | ||
fun data(): Collection<Array<Any>> { | ||
val field = Throwable::class.java.getDeclaredField("cause") | ||
field.isAccessible = true | ||
return listOf( | ||
run { | ||
val e = TestThrowable(0, null) | ||
arrayOf("Simple exception with no cause", e, listOf(e)) | ||
}, | ||
run { | ||
var e: TestThrowable? = null | ||
val exceptions = (0 until 10).map { | ||
e = TestThrowable(it, e) | ||
e | ||
} | ||
arrayOf("Exception with cause list", e!!, exceptions.asReversed()) | ||
}, | ||
run { | ||
val e = TestThrowable(0, null) | ||
field.set(e, e) | ||
arrayOf("Exception caused by itself", e, listOf(e)) | ||
}, | ||
run { | ||
val stack = mutableListOf<TestThrowable>() | ||
var e: TestThrowable? = null | ||
for(i in 0 until 10) { | ||
e = TestThrowable(i, stack.lastOrNull()) | ||
stack.add(e!!) | ||
} | ||
field.set(stack[0], stack[4]) | ||
arrayOf("Exception with loop in cause list", e!!, stack.asReversed()) | ||
}) | ||
} | ||
} | ||
|
||
@Test(timeout = 1000) | ||
fun test() { | ||
Assert.assertEquals(expectedExceptionSequence, e.walkExceptionCausedByList().asSequence().toList()) | ||
} | ||
} |