Closed ieluw closed 2 years ago
This is a bug in the Jsonnet files. They pass a function value to a %s
interpolation which is supposed to fail:
$ echo '"%1s" % function() "foo"' | jsonnet -
RUNTIME ERROR: couldn't manifest function in JSON output.
std.jsonnet:36:49 function <anonymous>
std.jsonnet:592:9-26 function <format_code>
std.jsonnet:722:15-60 thunk <s>
std.jsonnet:727:24 thunk <str>
std.jsonnet:480:30-33
std.jsonnet:480:19-34 thunk <w>
std.jsonnet:476:11 thunk <w>
std.jsonnet:472:12 function <aux>
std.jsonnet:476:7-17 function <padding>
std.jsonnet:480:7-38 function <pad_left>
std.jsonnet:727:15-39 thunk <s_padded>
std.jsonnet:733:55-63 thunk <v>
std.jsonnet:733:11-64 function <format_codes_arr>
std.jsonnet:733:11-64 function <format_codes_arr>
std.jsonnet:781:7-48 function <anonymous>
std.jsonnet:237:7-23 function <anonymous>
<stdin>:1:1-25
Sjsonnet erroneously accepts this and silently evaluates a nullary function, just like in https://github.com/databricks/sjsonnet/issues/120.
The specification defers to Python for std.format
, which shows yet another behavior:
$ python -c '"%1s" % (lambda : "foo")'
The function value is accepted and converted to a string, but it's an empty string, the function is not evaluated.
The error message by jsonnet is misleading. Functions are disallowed as values in std.format
but they can be manifested:
$ echo "function() 42" | jsonnet -
42
I happened to use jsonnet to compile Runbot's jsonnet file, which was failing but passed for sjsonnect.
The command I used:
and the error message from jsonnet is: