Skip to content

Commit 123e17f

Browse files
Improve error messages in Materializer (#238)
1 parent 680b1a8 commit 123e17f

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

sjsonnet/src/sjsonnet/Materializer.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ abstract class Materializer {
3737
)
3838
if(sort) {
3939
if(prevKey != null && k.compareTo(prevKey) <= 0)
40-
Error.fail(s"""Internal error: Unexpected key "$k" after "$prevKey" in sorted object materialization""")
40+
Error.fail(
41+
s"""Internal error: Unexpected key "$k" after "$prevKey" in sorted object materialization""", v.pos)
4142
prevKey = k
4243
}
4344
}
@@ -56,14 +57,14 @@ abstract class Materializer {
5657
case Val.True(pos) => storePos(pos); visitor.visitTrue(-1)
5758
case Val.False(pos) => storePos(pos); visitor.visitFalse(-1)
5859
case Val.Null(pos) => storePos(pos); visitor.visitNull(-1)
59-
case _: Val.Func =>
60-
Error.fail("Couldn't manifest function as JSON")
60+
case s: Val.Func =>
61+
Error.fail("Couldn't manifest function with params [" + s.params.names.mkString(",") + "]", v.pos)
6162
case _ =>
62-
Error.fail("Unknown value type " + v.prettyName)
63+
Error.fail("Unknown value type", v.pos)
6364
}
6465
} catch {
6566
case _: StackOverflowError =>
66-
Error.fail("Stackoverflow while materializing, possibly due to recursive value")
67+
Error.fail("Stackoverflow while materializing, possibly due to recursive value", v.pos)
6768
}
6869

6970
def reverse(pos: Position, v: ujson.Value): Val = v match{

sjsonnet/test/src-jvm/sjsonnet/ErrorTestsJvmOnly.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ object ErrorTestsJvmOnly extends TestSuite {
2323
val tests = Tests{
2424
test("array_recursive_manifest") - check(
2525
"""sjsonnet.Error: Stackoverflow while materializing, possibly due to recursive value
26+
| at .(sjsonnet/test/resources/test_suite/error.array_recursive_manifest.jsonnet:17:12)
2627
|""".stripMargin
2728
)
2829
test("obj_recursive") - check(
2930
"""sjsonnet.Error: Stackoverflow while materializing, possibly due to recursive value
31+
| at .(sjsonnet/test/resources/test_suite/error.obj_recursive.jsonnet:17:3)
3032
|""".stripMargin
3133
)
3234
test("obj_recursive_manifest") - check(
3335
"""sjsonnet.Error: Stackoverflow while materializing, possibly due to recursive value
36+
| at .(sjsonnet/test/resources/test_suite/error.obj_recursive_manifest.jsonnet:17:3)
3437
|""".stripMargin
3538
)
3639
}

sjsonnet/test/src/sjsonnet/EvaluatorTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ object EvaluatorTests extends TestSuite{
3030
eval("local f(x) = function() true; f(42)") ==> ujson.True
3131
eval("local f(x) = function() true; f(42) == true") ==> ujson.False
3232
eval("local f(x) = function() true; f(42)() == true") ==> ujson.True
33-
assert(evalErr("{foo: function() true}").startsWith("sjsonnet.Error: Couldn't manifest function as JSON"))
33+
assert(evalErr("{foo: function() true}").startsWith("sjsonnet.Error: Couldn't manifest function with params"))
3434
eval("{foo: (function() true)()}") ==> ujson.Obj{"foo" -> ujson.True}
3535
}
3636
test("members") {

0 commit comments

Comments
 (0)