mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-04 14:33:34 +00:00
Improve error handling by using decode::Error instead of io::Result (#2078)
Use decode::Error instead of io::Result
This commit is contained in:
parent
84dadffa81
commit
af8dbf7789
|
@ -1,3 +1,4 @@
|
||||||
|
use sd_p2p::proto::decode;
|
||||||
use tokio::io::{AsyncRead, AsyncReadExt};
|
use tokio::io::{AsyncRead, AsyncReadExt};
|
||||||
|
|
||||||
// will probs have more variants in future
|
// will probs have more variants in future
|
||||||
|
@ -8,14 +9,13 @@ pub enum SyncMessage {
|
||||||
|
|
||||||
impl SyncMessage {
|
impl SyncMessage {
|
||||||
// TODO: Per field errors for better error handling
|
// 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)) -> Result<Self, decode::Error> {
|
||||||
pub async fn from_stream(stream: &mut (impl AsyncRead + Unpin)) -> std::io::Result<Self> {
|
|
||||||
match stream.read_u8().await? {
|
match stream.read_u8().await? {
|
||||||
b'N' => Ok(Self::NewOperations),
|
b'N' => Ok(Self::NewOperations),
|
||||||
header => Err(std::io::Error::new(
|
header => Err(decode::Error::IoError(std::io::Error::new(
|
||||||
std::io::ErrorKind::InvalidData,
|
std::io::ErrorKind::InvalidData,
|
||||||
format!("Invalid sync message header: {}", (header as char)),
|
format!("Invalid sync message header: {}", (header as char)),
|
||||||
)),
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue