Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit be908fa5 authored by Martin Geisler's avatar Martin Geisler Committed by Automerger Merge Worker
Browse files

pdl: Propagate parse errors to callers am: 04a76214

parents 28eee400 04a76214
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -167,12 +167,19 @@ impl<'a> FieldParser<'a> {
                    }
                }
                ast::FieldDesc::Typedef { id, type_id } => {
                    // TODO(mgeisler): Remove the `unwrap` from the
                    // generated code and return the error to the
                    // caller.
                    let field_name = id;
                    let type_name = type_id;
                    let packet_name = &self.packet_name;
                    let id = format_ident!("{id}");
                    let type_id = format_ident!("{type_id}");
                    quote! { let #id = #type_id::try_from(#v).unwrap(); }
                    quote! {
                        let #id = #type_id::try_from(#v).map_err(|_| Error::InvalidEnumValueError {
                            obj: #packet_name.to_string(),
                            field: #field_name.to_string(),
                            value: #v as u64,
                            type_: #type_name.to_string(),
                        })?;
                    }
                }
                ast::FieldDesc::Reserved { .. } => {
                    if single_value {
+8 −1
Original line number Diff line number Diff line
@@ -129,7 +129,14 @@ impl BarData {
                got: bytes.get().remaining(),
            });
        }
        let x = Foo::try_from(bytes.get_mut().get_uint(3) as u32).unwrap();
        let x = Foo::try_from(bytes.get_mut().get_uint(3) as u32).map_err(|_| {
            Error::InvalidEnumValueError {
                obj: "Bar".to_string(),
                field: "x".to_string(),
                value: bytes.get_mut().get_uint(3) as u32 as u64,
                type_: "Foo".to_string(),
            }
        })?;
        Ok(Self { x })
    }
    fn write_to(&self, buffer: &mut BytesMut) {
+8 −1
Original line number Diff line number Diff line
@@ -129,7 +129,14 @@ impl BarData {
                got: bytes.get().remaining(),
            });
        }
        let x = Foo::try_from(bytes.get_mut().get_uint_le(3) as u32).unwrap();
        let x = Foo::try_from(bytes.get_mut().get_uint_le(3) as u32).map_err(|_| {
            Error::InvalidEnumValueError {
                obj: "Bar".to_string(),
                field: "x".to_string(),
                value: bytes.get_mut().get_uint_le(3) as u32 as u64,
                type_: "Foo".to_string(),
            }
        })?;
        Ok(Self { x })
    }
    fn write_to(&self, buffer: &mut BytesMut) {
+7 −1
Original line number Diff line number Diff line
@@ -114,7 +114,13 @@ impl BarData {
                got: bytes.get().remaining(),
            });
        }
        let x = Foo::try_from(bytes.get_mut().get_u64()).unwrap();
        let x =
            Foo::try_from(bytes.get_mut().get_u64()).map_err(|_| Error::InvalidEnumValueError {
                obj: "Bar".to_string(),
                field: "x".to_string(),
                value: bytes.get_mut().get_u64() as u64,
                type_: "Foo".to_string(),
            })?;
        Ok(Self { x })
    }
    fn write_to(&self, buffer: &mut BytesMut) {
+8 −1
Original line number Diff line number Diff line
@@ -114,7 +114,14 @@ impl BarData {
                got: bytes.get().remaining(),
            });
        }
        let x = Foo::try_from(bytes.get_mut().get_u64_le()).unwrap();
        let x = Foo::try_from(bytes.get_mut().get_u64_le()).map_err(|_| {
            Error::InvalidEnumValueError {
                obj: "Bar".to_string(),
                field: "x".to_string(),
                value: bytes.get_mut().get_u64_le() as u64,
                type_: "Foo".to_string(),
            }
        })?;
        Ok(Self { x })
    }
    fn write_to(&self, buffer: &mut BytesMut) {
Loading