Preserve VM throw sites in stack traces
This commit is contained in:
1 parent
fada848907
commit
b42ceec686
11 files changed
+137
-14
No files matched your search
@@ -5261,6 +5261,35 @@ class ScriptTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUnexpectedThrowablePreservesThrowSiteStackTrace() = runTest {
|
||||
val caught = evalNamed(
|
||||
"baderrorstack", """
|
||||
fun boom() {
|
||||
val arr = [10, 20, 30]
|
||||
arr[10]
|
||||
}
|
||||
try {
|
||||
boom()
|
||||
"unreachable"
|
||||
} catch (e) {
|
||||
e
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
val trace = caught.getLyngExceptionMessageWithStackTrace()
|
||||
assertContains(trace, "\n at baderrorstack:3:1: arr[10]")
|
||||
assertContains(trace, "\n at baderrorstack:6:1: boom()")
|
||||
assertFalse(trace.contains("catch (e)"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptErrorMessageTrimsSourceIndent() = runTest {
|
||||
val x = ScriptError(Pos(Source("trimraw", " arr[10]"), 0, 4), "boom")
|
||||
assertContains(x.message!!, "\narr[10]\n")
|
||||
assertFalse(x.message!!.contains("\n arr[10]\n"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMapIteralAmbiguity() = runTest {
|
||||
eval(
|
||||
|
||||
@@ -22,6 +22,8 @@ import net.sergeych.lyng.bridge.globalBinder
|
||||
import net.sergeych.lyng.obj.ObjVoid
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class PrintlnOverrideTest {
|
||||
|
||||
@@ -84,4 +86,46 @@ class PrintlnOverrideTest {
|
||||
|
||||
assertEquals(listOf("gb top level", "gb inside function"), output)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testExceptionPrintStackTraceFormatsPrimaryFrameBlock() = runTest {
|
||||
val scope = Script.newScope()
|
||||
val output = mutableListOf<String>()
|
||||
|
||||
scope.globalBinder().bindGlobalFun("println") {
|
||||
val sb = StringBuilder()
|
||||
for (i in 0 until args.size) {
|
||||
if (i > 0) sb.append(" ")
|
||||
sb.append(string(i))
|
||||
}
|
||||
output.add(sb.toString())
|
||||
ObjVoid
|
||||
}
|
||||
|
||||
scope.eval(
|
||||
"""
|
||||
fun boom() {
|
||||
val arr = [10, 20, 30]
|
||||
var a = 10
|
||||
var b = arr[a]
|
||||
b
|
||||
}
|
||||
try {
|
||||
boom()
|
||||
} catch (e) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
assertTrue(output.isNotEmpty())
|
||||
assertEquals(
|
||||
"IndexOutOfBoundsException: Index 10 out of bounds for length 3 at eval:4:9:",
|
||||
output[0]
|
||||
)
|
||||
assertEquals("var b = arr[a]", output[1])
|
||||
assertEquals("--------^", output[2])
|
||||
assertTrue(output.size >= 4)
|
||||
assertFalse(output.any { it == " at eval:4:9: var b = arr[a]" })
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user