chaokunyang commented on code in PR #2765:
URL: https://github.com/apache/fory/pull/2765#discussion_r2429593924
##########
rust/fory-derive/src/object/derive_enum.rs:
##########
@@ -53,26 +53,26 @@ pub fn gen_write_data(data_enum: &DataEnum) -> TokenStream {
let variant_idents: Vec<_> = data_enum.variants.iter().map(|v|
&v.ident).collect();
let variant_values: Vec<_> = (0..variant_idents.len()).map(|v| v as
u32).collect();
quote! {
- match self {
+ Ok(match self {
#(
Self::#variant_idents => {
context.writer.write_varuint32(#variant_values);
}
)*
- }
+ })
}
}
pub fn gen_read_data(data_enum: &DataEnum) -> TokenStream {
let variant_idents: Vec<_> = data_enum.variants.iter().map(|v|
&v.ident).collect();
let variant_values: Vec<_> = (0..variant_idents.len()).map(|v| v as
u32).collect();
quote! {
- let ordinal = context.reader.read_varuint32();
+ let ordinal = context.reader.read_varuint32()?;
match ordinal {
#(
#variant_values => Ok(Self::#variant_idents),
)*
- _ => panic!("unknown value"),
+ _ => fory_core::bail!("unknown enum value"),
Review Comment:
this should return `UnknownEnum` error
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]