propagates errors out of Packet::from_data (#13445)

Packet::from_data is ignoring serialization errors:
https://github.com/solana-labs/solana/blob/d08c3232e/sdk/src/packet.rs#L42-L48
This is likely never useful as the packet will be sent over the wire
taking bandwidth but at the receiving end will either fail to
deserialize or it will be invalid.
This commit will propagate the errors out of the function to the
call-site, allowing the call-site to handle the error.
This commit is contained in:
behzad nouri
2020-11-08 15:10:03 +00:00
committed by GitHub
parent 737d3e376d
commit 73ac104df2
2 changed files with 31 additions and 20 deletions

View File

@ -39,12 +39,10 @@ impl Packet {
Self { data, meta }
}
pub fn from_data<T: Serialize>(dest: &SocketAddr, data: T) -> Self {
let mut me = Packet::default();
if let Err(e) = Self::populate_packet(&mut me, Some(dest), &data) {
logger::error!("Couldn't write to packet {:?}. Data skipped.", e);
}
me
pub fn from_data<T: Serialize>(dest: &SocketAddr, data: T) -> Result<Self> {
let mut packet = Packet::default();
Self::populate_packet(&mut packet, Some(dest), &data)?;
Ok(packet)
}
pub fn populate_packet<T: Serialize>(