Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions sjsonnet/src/sjsonnet/Error.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ object Error {

def failIfNonEmpty(names: collection.BitSet,
outerOffset: Int,
formatMsg: (String, String) => String)
formatMsg: (String, String) => String,
// Allows the use of a custom file scope for computing the error message
// for details see: https://github.com/databricks/sjsonnet/issues/83
customFileScope: Option[FileScope] = None)
(implicit fileScope: FileScope, eval: EvalErrorScope) = if (names.nonEmpty){
val plural = if (names.size > 1) "s" else ""
val nameSnippet = names.map(fileScope.indexNames).mkString(", ")
val nameSnippet = names.map(customFileScope.getOrElse(fileScope).indexNames).mkString(", ")
fail(formatMsg(plural, nameSnippet), outerOffset)
}

Expand Down
3 changes: 2 additions & 1 deletion sjsonnet/src/sjsonnet/Val.scala
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ object Val{
Error.failIfNonEmpty(
repeats,
outerOffset,
(plural, names) => s"Function parameter$plural $names passed more than once"
(plural, names) => s"binding parameter a second time: $names",
Some(defSiteFileScope)
)

Error.failIfNonEmpty(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
local f = import "single_param_function.jsonnet";
f(1, x = "foo")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function(x) x
30 changes: 8 additions & 22 deletions sjsonnet/test/src-jvm/sjsonnet/ErrorTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,14 @@ object ErrorTests extends TestSuite{
)

test("function_duplicate_arg") - check(
"""sjsonnet.Error: Function parameter x passed more than once
"""sjsonnet.Error: binding parameter a second time: x
| at .(sjsonnet/test/resources/test_suite/error.function_duplicate_arg.jsonnet:17:21)
| at .(sjsonnet/test/resources/test_suite/error.function_duplicate_arg.jsonnet:17:21)
|""".stripMargin
)
test("function_duplicate_param") - check(
"""Parse error: Expected no duplicate parameter: x:17:14, found ") x\n"""".stripMargin
)
// test("function_infinite_default") - check(
// """sjsonnet.Error: Parameter passed more than once: x
// | at .(sjsonnet/test/resources/test_suite/error.function_duplicate_arg.jsonnet:17:2)
// | at .(sjsonnet/test/resources/test_suite/error.function_duplicate_arg.jsonnet:17:21)
// |""".stripMargin
// )
test("function_too_many_args") - check(
"""sjsonnet.Error: Too many args, function has 2 parameter(s)
| at .(sjsonnet/test/resources/test_suite/error.function_too_many_args.jsonnet:19:4)
Expand Down Expand Up @@ -288,20 +282,12 @@ object ErrorTests extends TestSuite{
| at .(sjsonnet/test/resources/imports/error.too_many_arg.jsonnet:3:6)
|""".stripMargin
)
// test("overflow") - check(
Comment thread
edsilfer marked this conversation as resolved.
// """sjsonnet.Error: my error message
// | at .(sjsonnet/test/resources/test_suite/error.invariant.simple3.jsonnet:18:10)
// |""".stripMargin
// )
// test("overflow2") - check(
// """sjsonnet.Error: my error message
// | at .(sjsonnet/test/resources/test_suite/error.invariant.simple3.jsonnet:18:10)
// |""".stripMargin
// )
// test("overflow3") - check(
// """sjsonnet.Error: my error message
// | at .(sjsonnet/test/resources/test_suite/error.invariant.simple3.jsonnet:18:10)
// |""".stripMargin
// )

test("too_many_arg_with_named_arg") - checkImports(
"""|sjsonnet.Error: binding parameter a second time: x
| at .(sjsonnet/test/resources/imports/error.too_many_arg_with_named_arg.jsonnet:2:2)
| at .(sjsonnet/test/resources/imports/error.too_many_arg_with_named_arg.jsonnet:2:2)
|""".stripMargin
)
}
}