Skip to content

Getting fields parsed so far on parser error #1121

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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