Skip to content

Commit

Permalink
Add CodecError, use from attribute in primary and replica errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan770 committed Jul 26, 2020
1 parent cde1813 commit 56ef71b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions spartan/src/node/replication/primary/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use tokio::io::Error as IoError;

#[derive(Error, Debug)]
pub enum PrimaryError {
#[error("Unable to serialize stream message: {0}")]
SerializationError(Box<ErrorKind>),
#[error("TCP connection error: {0}")]
SocketError(IoError),
#[error("Socket codec error")]
CodecError(#[from] Box<ErrorKind>),
#[error("TCP connection error")]
SocketError(#[from] IoError),
#[error("TCP socket is empty")]
EmptySocket,
#[error("Protocol mismatch")]
Expand Down
6 changes: 3 additions & 3 deletions spartan/src/node/replication/primary/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ impl<'a> Stream {
self.0
.send(Request::Primary(message))
.await
.map_err(PrimaryError::SerializationError)?;
.map_err(PrimaryError::CodecError)?;

SinkExt::<Request>::flush(&mut self.0)
.await
.map_err(PrimaryError::SerializationError)?;
.map_err(PrimaryError::CodecError)?;

let buf = match self.0.next().await {
Some(r) => r.map_err(PrimaryError::SerializationError)?,
Some(r) => r.map_err(PrimaryError::CodecError)?,
None => return Err(PrimaryError::EmptySocket),
};

Expand Down
12 changes: 6 additions & 6 deletions spartan/src/node/replication/replica/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ use tokio::io::Error as IoError;

#[derive(Error, Debug)]
pub enum ReplicaError {
#[error("Manager persistence error: {0}")]
PersistenceError(PersistenceError),
#[error("Manager persistence error")]
PersistenceError(#[from] PersistenceError),
#[error("Unable to find replica node config")]
ReplicaConfigNotFound,
#[error("TCP socket error: {0}")]
SocketError(IoError),
#[error("TCP socket error")]
SocketError(#[from] IoError),
#[error("Empty TCP socket")]
EmptySocket,
#[error("Packet serialization error: {0}")]
SerializationError(Box<ErrorKind>),
#[error("Socket codec error")]
CodecError(#[from] Box<ErrorKind>),
#[error("Protocol mismatch")]
ProtocolMismatch,
}
Expand Down
6 changes: 3 additions & 3 deletions spartan/src/node/replication/replica/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<'a> ReplicaSocket<'a> {
Fut: Future<Output = ReplicaRequest<'a>>,
{
let buf = match self.socket.next().await {
Some(r) => r.map_err(ReplicaError::SerializationError)?,
Some(r) => r.map_err(ReplicaError::CodecError)?,
None => return Err(ReplicaError::EmptySocket),
};

Expand All @@ -79,11 +79,11 @@ impl<'a> ReplicaSocket<'a> {
self.socket
.send(Request::Replica(request))
.await
.map_err(ReplicaError::SerializationError)?;
.map_err(ReplicaError::CodecError)?;

SinkExt::<Request>::flush(&mut self.socket)
.await
.map_err(ReplicaError::SerializationError)?;
.map_err(ReplicaError::CodecError)?;

Ok(())
}
Expand Down

0 comments on commit 56ef71b

Please sign in to comment.