cleanup API for arc based error type (#469)

Co-authored-by: Jane Lusby <jane@zfnd.org>
This commit is contained in:
Jane Lusby 2020-06-12 11:29:42 -07:00 committed by GitHub
parent 334329f38a
commit 4b9e4520ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -79,7 +79,7 @@ impl Handler {
GetBlocksByHash { hashes, blocks }
}
} else {
Finished(Err(Arc::new(PeerError::WrongBlock).into()))
Finished(Err(PeerError::WrongBlock.into()))
}
}
(FindBlocks, Message::Inv(inv_hashes)) => Finished(Ok(Response::BlockHeaderHashes(
@ -227,7 +227,7 @@ where
}
// Other request timeouts fail the request.
State::AwaitingResponse(_, tx) => {
let _ = tx.send(Err(Arc::new(e).into()));
let _ = tx.send(Err(e.into()));
State::AwaitingRequest
}
_ => unreachable!(),
@ -267,7 +267,7 @@ where
if guard.is_some() {
panic!("called fail_with on already-failed connection state");
} else {
*guard = Some(Arc::new(e).into());
*guard = Some(e.into());
}
// Drop the guard immediately to release the mutex.
std::mem::drop(guard);

View File

@ -7,7 +7,16 @@ use zebra_chain::serialization::SerializationError;
/// A wrapper around `Arc<PeerError>` that implements `Error`.
#[derive(Error, Debug, Clone)]
#[error("{0}")]
pub struct SharedPeerError(#[from] Arc<PeerError>);
pub struct SharedPeerError(Arc<PeerError>);
impl<E> From<E> for SharedPeerError
where
PeerError: From<E>,
{
fn from(source: E) -> Self {
Self(Arc::new(PeerError::from(source)))
}
}
/// An error related to peer connection handling.
#[derive(Error, Debug)]