Skip to content

Mismatched braces disrupt parse_sup of individual values #6234

@philrz

Description

@philrz

The 1 and final error value in this output indicates a parse_sup bug.

$ echo "
{\"foo\":{1}
{\"bar\":1}
" | super -i line -c "split(this, '\n') | parse_sup(this[1])" -

null
error({message:"parse_sup: parse error: mismatched braces while parsing record type",on:"{\"foo\":{1}"})
1
error({message:"parse_sup: SUP syntax error",on:""})

Details

Repro is with super commit 0e9052b. This issue was reported by a user in a community Slack thread.

The user's goal in their words:

I have a text file that should be mostly valid json (one compact row per line), but some lines are not due to Reasons.
So I’m experimenting with a way to parse the valid json lines and skip the invalid ones.

Taken individually, we can confirm that the first and last lines should each parse to null, the second is invalid due to mismatched braces and we should expect an error, and the third is valid and should parse to a record.

$ echo "" | super -i line -c "split(this, '\n')" -
[""]

$ echo "{\"foo\":{1}" | super -i line -c "split(this, '\n') | parse_sup(this[1])" -
error({message:"parse_sup: parse error: mismatched braces while parsing record type",on:"{\"foo\":{1}"})

$ echo "{\"bar\":1}" | super -i line -c "split(this, '\n') | parse_sup(this[1])" -
{bar:1}

Taking the input as a whole, we can also confirm the input can be treated as individual text values via line input.

$ echo "
{\"foo\":{1}
{\"bar\":1}
" | super -i line -c "split(this, '\n')" -

[""]
["{\"foo\":{1}"]
["{\"bar\":1}"]
[""]

However, as the user observed about the original repro:

when I try to parse each line individually, the invalid line somehow affects the later valid ones:

@nwt saw the repro and confirmed that it's a bug in parse_sup holding on to state it shouldn’t be after the brace error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions