Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialization error loses information after being passed through the erased API #110

Open
fjarri opened this issue Jan 8, 2025 · 0 comments

Comments

@fjarri
Copy link

fjarri commented Jan 8, 2025

I noticed it when using postcard with erased-serde, but other formats may be susceptible to the same problem.

postcard::Error is an enum with a bunch of variants. It implements serde::de::Error, but the custom() method just ignores its msg argument and creates a postcard::Error::SerdeSerCustom.

Now, in erased-serde if there's an error during deserialization, it's passed through erase_de which calls serde::de::Error::custom(). So whatever information there was in the error is now lost.

My question is: is it technically a bug in postcard, and it should implement custom() without ignoring the message, even though it never uses this method itself? Or can it be fixed in erased-serde? The latter can be done by storing Box<dyn Any> in erased_serde::Error instead of Box<ErrorImpl>, and then downcasting it back in unerase_de(), but that would require either an .expect() (which I think should be safe, but does not look good in the code), or making unerase_de() fallible, passing the downcasting error to the deserializer (something that will never happen unless there's a bug in the code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant