Skip to content

Repetition in nested error messages #21

Description

@andrewhickman

I'm trying to implement a kind of user-extensible deserialization that allows you to "plug in" extra deserialize implementations. The basic idea is to have a Seed struct containing a HashMap<String, fn (&Seed, &mut erased_serde::Deserializer) -> erased_serde::Error> and use serde::DeserializeSeed to deserialize stuff. This is working pretty well, but there's an annoying issue with the error handling.

Whenever I call one of the deserialize implementations I can get an erased_serde::Error, but to bubble it up I need to convert it to an error for the deserializer I am using (serde_json at the moment, but I would like to remain generic), by using serde::de::Error::custom. These calls can be fairly recursive, so I might end up going back-and-forth between the two error types a few times. This is giving me error messages that look like this:

Error("trailing comma at line 32 column 41 at line 32 column 41 at line 33 column 37 at line 34 column 33 at line 35 column 29 at line 36 column 25 at line 36 column 25 at line 36 column 25 at line 36 column 25", line: 36, column: 25)

The ideal solution for me would be the ability to cast erased_serde::Error back to the original error type, by representing it as a Box<serde::de::Error>. I'm not sure whether my use-case is typical for this library so possibly this makes no sense in the general case, but I am interested to know what you think.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions