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

feat: return tagged variant deserde error #1810

Merged
merged 2 commits into from
Dec 23, 2024
Merged

Conversation

mattsse
Copy link
Member

@mattsse mattsse commented Dec 18, 2024

modifies the derived untagged impl to return the tagged attempt error, which is more useful that the generated "data did not match any variant of untagged enum MaybeTaggedTxEnvelope".

this requires private serde API but this should be okay because this is what untagged expands to.
we could technically make this work if we handroll deserde entirely but would be more error prone

    impl<'de> _serde::Deserialize<'de> for MaybeTaggedTxEnvelope {
            fn deserialize<__D>(
                __deserializer: __D,
            ) -> _serde::__private::Result<Self, __D::Error>
            where
                __D: _serde::Deserializer<'de>,
            {
                let __content = <_serde::__private::de::Content as _serde::Deserialize>::deserialize(
                    __deserializer,
                )?;
                let __deserializer = _serde::__private::de::ContentRefDeserializer::<
                    __D::Error,
                >::new(&__content);
                if let _serde::__private::Ok(__ok)
                    = _serde::__private::Result::map(
                        <TaggedTxEnvelope as _serde::Deserialize>::deserialize(
                            __deserializer,
                        ),
                        MaybeTaggedTxEnvelope::Tagged,
                    ) {
                    return _serde::__private::Ok(__ok);
                }
                if let _serde::__private::Ok(__ok)
                    = _serde::__private::Result::map(
                        <UntaggedLegacy as _serde::Deserialize>::deserialize(
                            __deserializer,
                        ),
                        MaybeTaggedTxEnvelope::Untagged,
                    ) {
                    return _serde::__private::Ok(__ok);
                }
                _serde::__private::Err(
                    _serde::de::Error::custom(
                        "data did not match any variant of untagged enum MaybeTaggedTxEnvelope",
                    ),
                )
            }
        }

@mattsse mattsse requested a review from klkvr December 23, 2024 18:21
@mattsse mattsse enabled auto-merge (squash) December 23, 2024 18:22
@mattsse mattsse merged commit e8ed23b into main Dec 23, 2024
26 checks passed
@mattsse mattsse deleted the matt/improve-untagged-deserde branch December 23, 2024 18:23
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

Successfully merging this pull request may close these issues.

2 participants