dtolnay / path-to-error

Find out path at which a deserialization error occurred
Apache License 2.0
320 stars 12 forks source link

Recursive enums lose path information #14

Closed mythmon closed 1 year ago

mythmon commented 2 years ago

This may be similar to #6 and #9.

When deserializing an enum that can recursively hold itself, like this:

enum Thing {
    Foo {
        inner: Option<Box<Thing>>,
        required_field: u32,
    },
    Bar,
}

The path returned for errors is . (a dot).

Both of these JSON strings returns the same error:

{
    "type": "Foo",
    "required_field": 1,
    "inner": {
        "type": "Foo",
        "inner": null
    }
}
{
    "type": "Foo",
    "inner": {
        "type": "Foo",
        "required_field": 2,
        "inner": null
    }
}

The first is missing required_field at the second level, and the second is missing at the top level. It is impossible to tell from the error where the problem is. The Display of the error is

.: missing field `required_field`

Full code to reproduce is here: https://gist.github.com/mythmon/e29581a739bdbbee237df11b39213d22

christos-h commented 2 years ago

If someone could point me in the right direction here I can take a shot at the fix.

dtolnay commented 1 year ago

Closing as a duplicate of #1.