Stream: ideas

Topic: Decode Errors


view this post on Zulip Luke Boswell (Mar 27 2023 at 07:53):

I have been thinking, should we have more than just a TooShort option for DecodeError to be more descriptive? Almost all decoders will be doing some kind of utf-8 parsing and then conversion to a RocType. Perhaps adding a BadUtf8, UnexpectedType and InvalidType as well as TooShort might be helpful?

view this post on Zulip Brendan Hansknecht (Mar 28 2023 at 09:33):

Can a decoder not specify its own error types?

view this post on Zulip Luke Boswell (Mar 28 2023 at 09:48):

Hmm, not sure. The type in the Decode builtin is currently DecodeError : [TooShort] which I think means it is open by default now. So I guess so?

view this post on Zulip Ayaz Hafiz (Mar 28 2023 at 12:19):

Yeah, we should have more error options. The current list was not meant to be exhaustive

view this post on Zulip Ayaz Hafiz (Mar 28 2023 at 12:20):

Decoders cannot specify their own error types because in order to do so we would need associated types on abilities, which we don’t intend to add.

view this post on Zulip Ayaz Hafiz (Mar 28 2023 at 12:20):

We could add a catch all “Other Str” error that decoders could use to fill in non-standard errors with

view this post on Zulip Richard Feldman (Mar 28 2023 at 12:39):

BadUtf8 is probably too specific, but maybe something about "the encoding was wrong" would be a good one

view this post on Zulip Richard Feldman (Mar 28 2023 at 12:39):

like MalformedContent or something

view this post on Zulip Brendan Hansknecht (Mar 28 2023 at 14:37):

How does serde in rust deal with this?

view this post on Zulip Ayaz Hafiz (Mar 28 2023 at 14:48):

associated types on deserializers

view this post on Zulip Ayaz Hafiz (Mar 28 2023 at 14:48):

https://docs.rs/serde/1.0.159/serde/trait.Deserializer.html


Last updated: Jun 16 2026 at 16:19 UTC