Commit 61e19a6
committed
THRIFT-XXXX: Rust codegen: forward-compatible union deserialization in structs
When a struct field has a union type, the generated Rust deserializer
now catches 'received empty union' errors from unknown variants and
treats them as None instead of propagating the error.
Previously, if a Thrift union received a field ID not present in the
local IDL, the union deserializer returned Err('received empty union'),
which cascaded up and caused the entire parent struct deserialization
to fail. This broke forward compatibility.
The fix wraps union field reads in struct deserializers with a match
that catches the specific 'received empty union' error and silently
skips the field. The struct field (already Option<UnionType>) remains
None, matching the behavior as if the field were absent. All other
errors (malformed data, I/O failures) still propagate normally.
Handles both direct union fields and Box<Union> (forward typedef)
fields by resolving the type before generating the method call.
This aligns Rust with Java, Go, Python, and C++ Thrift behavior.1 parent 6f18285 commit 61e19a6
1 file changed
Lines changed: 29 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1699 | 1699 | | |
1700 | 1700 | | |
1701 | 1701 | | |
| 1702 | + | |
| 1703 | + | |
1702 | 1704 | | |
1703 | 1705 | | |
1704 | | - | |
1705 | | - | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
1706 | 1733 | | |
1707 | 1734 | | |
1708 | 1735 | | |
| |||
0 commit comments