Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON decode on run_sh output #2434

Closed
xavier-romero opened this issue May 7, 2024 · 4 comments
Closed

JSON decode on run_sh output #2434

xavier-romero opened this issue May 7, 2024 · 4 comments
Assignees
Labels
bug Something isn't working cli For bugs relating to the CLI painful Painful bug

Comments

@xavier-romero
Copy link

What's your CLI version?

0.89.3

Description & steps to reproduce

By running that plan:

def run(plan):
    x = plan.run_sh(
        run="""
        echo '{"key":"value"}'
        """
    )
    a = x.output
    plan.print(a)
    plan.print(a[:])
    plan.print(a[0:-1])
    plan.print(a[0:-1]+a[-1])

I get these outputs:

{"key":"value"}
{"key":"value"}
{{kurtosis:b0597720154d47fc9701d3bec6c15dc2:output.runtime_value}
{"key":"value"}

Specially surprised with the 4th result not being like the 3rf tbh ':--o

When trying to decode json output like this:

def run(plan):
    x = plan.run_sh(
        run="""
        echo '{"key":"value"}'
        """
    )
    a = x.output
    json.decode(a)

I get an error:
Evaluation error: json.decode: at offset 2, unexpected character 'k'

For some reason when trying to decode it's using that internal reference instead of the resulting string.

Desired behavior

To decode the output string instead of the internal object reference.

What is the severity of this bug?

Painful; this is causing significant friction in my workflow.

What area of the product does this pertain to?

CLI: the Command Line Interface

@xavier-romero xavier-romero added the bug Something isn't working label May 7, 2024
@github-actions github-actions bot added cli For bugs relating to the CLI painful Painful bug labels May 7, 2024
@laurentluce laurentluce self-assigned this May 9, 2024
@laurentluce
Copy link
Contributor

@tedim52 explained to me that Starlark cannot interpret string slices. All the print commands operate on the full a output except the third one so the result is expected.

@laurentluce
Copy link
Contributor

A future reference cannot be decoded so the exact output will have to be returned as part of plan.run_sh with the help of jq for example.

@laurentluce
Copy link
Contributor

laurentluce commented May 13, 2024

We are aware that future reference / string manipulation is not great today.

@laurentluce
Copy link
Contributor

Duplicate of #2049

@laurentluce laurentluce marked this as a duplicate of #2049 May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cli For bugs relating to the CLI painful Painful bug
Projects
None yet
Development

No branches or pull requests

2 participants