Skip to content

Getting fields parsed so far on parser error #1121

@dariusarnold

Description

@dariusarnold

Is there a way to get everything parsed so far (kind of like Probe() does) when an error is raised during parsing?
Simple example of what I am looking for:

import construct as cs

Test = cs.Struct(
    "a" / cs.Byte,
    "b" / cs.Byte,
)

try:
    # Only one byte in input
    result = Test.parse(b"1")
except Exception as e:
    print(e.parsed_so_far)

This would print

Container: 
    a = 49

I looked around the codebase, and the exceptions raised currently don't contain this information. Maybe there is some other way?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions