% in multiline bash string leads to error

341 views
Skip to first unread message

Andreas Kapp

unread,
Sep 27, 2018, 3:53:53 AM9/27/18
to Jsonnet
I have this 'demo.jsonnet' file which I call like this (you have to create the target folder): 

jsonnet demo.jsonnet -S -m target


{
[host]: |||
#!/bin/bash
# This is %(h)s file
# SET timestamp
export TIMESTAMP=$(date +%F)
echo $TIMESTAMP
||| % { h: host } for host in ['demo.sh']

}


It produces this error:

jsonnet demo.jsonnet -S -m target
RUNTIME ERROR: Mapping keys required.
        <std>:712:15-45 thunk <f> from <function <format_codes_obj>>
        <std>:726:38-39 thunk from <thunk <val> from <function <format_codes_obj>>>
        <std>:1185:24-25        thunk from <function <anonymous>>
        <std>:1185:5-32 function <anonymous>
        <std>:726:16-40 thunk <val> from <function <format_codes_obj>>
        <std>:734:27-30 thunk from <thunk <s> from <function <format_codes_obj>>>
        <std>:585:21-24 thunk from <function <format_code>>
        <std>:585:12-25 function <format_code>

        <std>:734:15-50 thunk <s> from <function <format_codes_obj>>
        ...
        <std>:465:12-13 function <aux>
        <std>:469:7-17  function <padding>
        <std>:473:7-38  function <pad_left>
        <std>:739:15-35 thunk <s_padded> from <function <format_codes_obj>>
        <std>:740:51-59 thunk from <function <format_codes_obj>>
        <std>:740:11-60 function <format_codes_obj>
        <std>:745:7-43  function <anonymous>
        <std>:225:7-23  function <anonymous>

        During manifestation



When I remove the % sign from the bash date function it works as expected.

Bug or feature?

Thanks, Andreas

Dave Cunningham

unread,
Sep 27, 2018, 7:08:20 AM9/27/18
to Andreas Kapp, Jsonnet
You need to do $(date +%%F)

What's happening is it is interpreting it as %F (i.e. floating point) but since you're doing % { ... } it's saying that the format specified %F does not have a mapping key, it's expecting it to be %(foo)F

The error message could be better!

--
You received this message because you are subscribed to the Google Groups "Jsonnet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonnet+unsubscribe@googlegroups.com.
To post to this group, send email to jso...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsonnet/a502b8d6-89a8-4a32-9c59-738733c282ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andreas Kapp

unread,
Sep 27, 2018, 7:35:52 AM9/27/18
to Jsonnet
Shouldn't every evaluation in a string happen only inside %()?

i'm happy I have a solution for this. Thanks.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonnet+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages