tools for error reporting in kotlin
This commit is contained in:
parent
eda34c1b3d
commit
2ce6d8e482
@ -89,6 +89,17 @@ open class ObjException(
|
||||
|
||||
override val objClass: ObjClass = exceptionClass
|
||||
|
||||
/**
|
||||
* Tool to get kotlin string with error report including the Lyng stack trace.
|
||||
*/
|
||||
suspend fun toStringWithStackTrace(): String {
|
||||
val l = getStackTrace().list
|
||||
return buildString {
|
||||
append(message.value)
|
||||
for( t in l)
|
||||
append("\n\tat ${t.toString(scope)}")
|
||||
}
|
||||
}
|
||||
override suspend fun defaultToString(scope: Scope): ObjString {
|
||||
val at = getStackTrace().list.firstOrNull()?.toString(scope)
|
||||
?: ObjString("(unknown)")
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2025 Sergey S. Chernov real.sergeych@gmail.com
|
||||
* Copyright 2026 Sergey S. Chernov real.sergeych@gmail.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -24,6 +24,7 @@ import net.sergeych.lyng.ExecutionError
|
||||
import net.sergeych.lyng.ScriptError
|
||||
import net.sergeych.lyng.eval
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
class MapLiteralTest {
|
||||
@ -42,6 +43,29 @@ class MapLiteralTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSimpleLiteral() = runTest {
|
||||
assertEquals("""{"a":1,"b":2}""", eval("{ a: 1, b: 2 }").toJson().toString())
|
||||
assertEquals("""{"a":1,"b":2}""", eval("""
|
||||
{
|
||||
a: 1,
|
||||
b: 2
|
||||
}
|
||||
""".trimIndent()).toJson().toString())
|
||||
assertEquals("""{"a":1,"b":2}""", eval("""
|
||||
object Contracts {
|
||||
val POR = object {
|
||||
fun f1() = 1
|
||||
fun f2() = 2
|
||||
}
|
||||
}
|
||||
{
|
||||
a: Contracts.POR.f1(),
|
||||
b: Contracts.POR.f2()
|
||||
}
|
||||
""".trimIndent()).toJson().toString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun spreadsAndOverwriteOrder() = runTest {
|
||||
eval(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user