diff --git a/core/src/p2p/sync/proto.rs b/core/src/p2p/sync/proto.rs index 33aa1647f980..883708fcc123 100644 --- a/core/src/p2p/sync/proto.rs +++ b/core/src/p2p/sync/proto.rs @@ -1,3 +1,4 @@ +use sd_p2p::proto::decode; use tokio::io::{AsyncRead, AsyncReadExt}; // will probs have more variants in future @@ -8,14 +9,13 @@ pub enum SyncMessage { impl SyncMessage { // TODO: Per field errors for better error handling - // TODO: Using `decode::Error` instead of `io::Result` - pub async fn from_stream(stream: &mut (impl AsyncRead + Unpin)) -> std::io::Result { + pub async fn from_stream(stream: &mut (impl AsyncRead + Unpin)) -> Result { match stream.read_u8().await? { b'N' => Ok(Self::NewOperations), - header => Err(std::io::Error::new( + header => Err(decode::Error::IoError(std::io::Error::new( std::io::ErrorKind::InvalidData, format!("Invalid sync message header: {}", (header as char)), - )), + ))), } }