Skip to content

Decoder stops parsing a file if a nested list has a length mismatch #47

@lcarsos

Description

@lcarsos

Description

I have a toon file that looks something like this:

groups[2]:
  - a: foo
    b[1]{w,x}:
      wince,0
  - a: bar
    b[0]{w,x}:
      wise,1
...

It's odd to me that I get the right error if it's the first entry in the list.

For the second "object" I just get the string "a: bar". Looking through the code it looks like that's because any ToonDecodeError that gets raised in any list gets swallowed on line 783 of decode_list_array that seems to just assume that this must just be some unquoted string.

I have a branch where I changed the type thrown in the array parser to at least not swallow length mismatches (https://github.com/lcarsos/toon-python/tree/fix/nested-array-obj) since otherwise you'd have to reraise through several levels but that doesn't feel like the right fix to me.

I also noticed another case where a nested error was swallowed like this, wanted to get your opinion on how you'd prefer this get tackled before I go off writing code that will never merge.

Reproduction Steps

decode file:

groups[2]:
  - a: foo
    b[1]{w,x}:
      wince,0
  - a: bar
    b[0]{w,x}:
      wise,1

Expected Behavior

Expected thrown error: "Expected 0 rows, but got 1"

Actual Behavior

No errors, but incorrectly parsed:

{
  "groups": [
    {
      "a": "foo",
      "b": [
        { "w": "wince", "x": 0 }
      ]
    },
    "a: bar"
  ]
}

Environment

python 3.14
both 0.9.0 and main

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions