Skip to content

Commit

Permalink
fix: Remove a few panics
Browse files Browse the repository at this point in the history
Those panics should not crash the node. Folding them in the error case of their immediately enclosing `Result`.
  • Loading branch information
huitseeker committed Jul 26, 2022
1 parent 9e02a2e commit 414123d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion crates/sui-core/src/authority_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ impl AuthorityServerHandle {
}

pub async fn kill(self) -> Result<(), std::io::Error> {
self.tx_cancellation.send(()).unwrap();
self.tx_cancellation.send(()).map_err(|_e| {
std::io::Error::new(io::ErrorKind::Other, "could not send cancellation signal!")
})?;
self.handle
.await?
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
Expand Down
3 changes: 2 additions & 1 deletion crates/sui-types/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@ where
{
fn from_signable_bytes(bytes: &[u8]) -> Result<Self, Error> {
// Remove name tag before deserialization using BCS
let name = serde_name::trace_name::<Self>().expect("Self must be a struct or an enum");
let name = serde_name::trace_name::<Self>()
.ok_or_else(|| anyhow::anyhow!("Self should be a struct or an enum"))?;
let name_byte_len = format!("{}::", name).bytes().len();
Ok(bcs::from_bytes(&bytes[name_byte_len..])?)
}
Expand Down

0 comments on commit 414123d

Please sign in to comment.