From aed2e61f53e0c37420e2082327263b78b302c4ab Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Fri, 18 Feb 2022 14:26:46 -0700 Subject: [PATCH] add an error type for enclave not initialized --- consensus/enclave/api/src/error.rs | 3 +++ consensus/enclave/impl/src/lib.rs | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/consensus/enclave/api/src/error.rs b/consensus/enclave/api/src/error.rs index 441e6e1ebd..f123ca0d55 100644 --- a/consensus/enclave/api/src/error.rs +++ b/consensus/enclave/api/src/error.rs @@ -55,6 +55,9 @@ pub enum Error { /// Invalid fee configuration: {0} FeeMap(FeeMapError), + + /// Enclave not initialized + NotInited, } impl From for Error { diff --git a/consensus/enclave/impl/src/lib.rs b/consensus/enclave/impl/src/lib.rs index 02e7d545a9..a8c1538e2f 100644 --- a/consensus/enclave/impl/src/lib.rs +++ b/consensus/enclave/impl/src/lib.rs @@ -219,7 +219,7 @@ impl ConsensusEnclave for SgxConsensusEnclave { .blockchain_config .lock()? .as_ref() - .expect("enclave was not initialized") + .ok_or(Error::NotInited)? .get_config() .fee_map .get_fee_for_token(token_id)) @@ -265,7 +265,7 @@ impl ConsensusEnclave for SgxConsensusEnclave { .blockchain_config .lock()? .as_ref() - .expect("enclave was not initialized") + .ok_or(Error::NotInited)? .responder_id(peer_id); Ok(self.ake.peer_init(&peer_id)?) @@ -285,7 +285,7 @@ impl ConsensusEnclave for SgxConsensusEnclave { .blockchain_config .lock()? .as_ref() - .expect("enclave was not initialized") + .ok_or(Error::NotInited)? .responder_id(peer_id); Ok(self.ake.peer_connect(&peer_id, msg)?) @@ -367,7 +367,7 @@ impl ConsensusEnclave for SgxConsensusEnclave { let blockchain_config = self.blockchain_config.lock()?; let config = blockchain_config .as_ref() - .expect("enclave was not initialized") + .ok_or(Error::NotInited)? .get_config(); // Enforce that all membership proofs provided by the untrusted system for