Skip to content

Commit

Permalink
Improve error handling by using decode::Error instead of io::Result (#…
Browse files Browse the repository at this point in the history
…2078)

Use decode::Error instead of io::Result
  • Loading branch information
julianbraha committed Feb 20, 2024
1 parent 84dadff commit af8dbf7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions core/src/p2p/sync/proto.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use sd_p2p::proto::decode;
use tokio::io::{AsyncRead, AsyncReadExt};

// will probs have more variants in future
Expand All @@ -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<Self> {
pub async fn from_stream(stream: &mut (impl AsyncRead + Unpin)) -> Result<Self, decode::Error> {
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)),
)),
))),
}
}

Expand Down

0 comments on commit af8dbf7

Please sign in to comment.