This is an automated email from the ASF dual-hosted git repository. mssun pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/incubator-teaclave.git
commit a99309d6a5fffe22a07d542527013d40d443dc41 Author: Mingshen Sun <[email protected]> AuthorDate: Sat Jan 18 20:35:27 2020 -0800 Polishing error handling code --- attestation/src/report.rs | 6 ++---- ipc/src/channel/app_dep.rs | 9 +++------ ipc/src/macros.rs | 3 +-- rpc/src/transport.rs | 4 ++-- utils/service_enclave_utils/src/lib.rs | 6 +++--- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/attestation/src/report.rs b/attestation/src/report.rs index 7237fde..9dd9abc 100644 --- a/attestation/src/report.rs +++ b/attestation/src/report.rs @@ -20,7 +20,7 @@ use std::prelude::v1::*; use crate::ias::IasReport; -use anyhow::{anyhow, bail}; +use anyhow::{anyhow, bail, ensure}; use anyhow::{Error, Result}; use chrono::DateTime; use rustls; @@ -196,9 +196,7 @@ impl SgxQuoteBody { *i = *_it.next().ok_or_else(|| anyhow!("Quote parsing error."))?; } - if pos != bytes.len() { - bail!("Quote parsing error."); - } + ensure!(pos == bytes.len(), "Quote parsing error."); Ok(Self { version, diff --git a/ipc/src/channel/app_dep.rs b/ipc/src/channel/app_dep.rs index 671870b..776d54b 100644 --- a/ipc/src/channel/app_dep.rs +++ b/ipc/src/channel/app_dep.rs @@ -25,8 +25,7 @@ use serde::Serialize; use sgx_types::{sgx_enclave_id_t, sgx_status_t}; use crate::IpcSender; -use anyhow; -use anyhow::Result; +use anyhow::{bail, Result}; use teaclave_types::EnclaveStatus; // Delaration of ecall for App, the implementation is in TEE @@ -92,7 +91,7 @@ impl ECallChannel { /* Check sgx return values */ if sgx_status != sgx_status_t::SGX_SUCCESS { error!("ecall_ipc_entry_point, app sgx_error:{}", sgx_status); - return Err(anyhow::anyhow!(sgx_status)); + bail!(sgx_status); } /* @@ -101,7 +100,6 @@ impl ECallChannel { * We only retry once for once invocation. */ if ecall_ret.is_err_ffi_outbuf() && !retried { - // TODO: let e = Error::from(ecall_ret); debug!( "ecall_ipc_entry_point, expand app request buffer size: {:?}", ecall_ret @@ -118,9 +116,8 @@ impl ECallChannel { * Transparent deliever the errors to outer logic. */ if ecall_ret.is_err() { - // let e = Error::from(ecall_ret); error!("ecall_ipc_entry_point, app api_error: {:?}", ecall_ret); - return Err(anyhow::anyhow!("ecall error")); // TODO + bail!("ecall error"); } unsafe { diff --git a/ipc/src/macros.rs b/ipc/src/macros.rs index 9716482..27a5ec8 100644 --- a/ipc/src/macros.rs +++ b/ipc/src/macros.rs @@ -26,7 +26,7 @@ macro_rules! register_ecall_handler { $( $cmd => dispatch_helper::<$arg, $ret>(input), )* - _ => return Err(anyhow::anyhow!("ECallCommandNotRegistered")), + _ => anyhow::bail!("ECallCommandNotRegistered"), } } use teaclave_ipc::IpcService; @@ -101,7 +101,6 @@ macro_rules! register_ecall_handler { Ok(out) => out, Err(e) => { error!("tee execute cmd: {:x}, error: {}", cmd, e); - // return e.into(); return teaclave_types::EnclaveStatus(1); } } diff --git a/rpc/src/transport.rs b/rpc/src/transport.rs index d97d6a2..6e0562e 100644 --- a/rpc/src/transport.rs +++ b/rpc/src/transport.rs @@ -31,7 +31,7 @@ mod sgx_trusted_tls { use crate::protocol; use crate::transport::{ClientTransport, ServerTransport}; use crate::TeaclaveService; - use anyhow::Result; + use anyhow::{bail, Result}; use log::debug; use rustls; use serde::{Deserialize, Serialize}; @@ -91,7 +91,7 @@ mod sgx_trusted_tls { debug!("Connection disconnected."); return Ok(()); } - _ => return Err(anyhow::anyhow!("InternalError")), + _ => bail!("InternalError"), }, }; let response = service.handle_request(request); diff --git a/utils/service_enclave_utils/src/lib.rs b/utils/service_enclave_utils/src/lib.rs index 4be6246..13e1f13 100644 --- a/utils/service_enclave_utils/src/lib.rs +++ b/utils/service_enclave_utils/src/lib.rs @@ -3,7 +3,7 @@ #[macro_use] extern crate sgx_tstd as std; -use anyhow::{anyhow, Result}; +use anyhow::{bail, Result}; use teaclave_service_config as config; use log::debug; @@ -31,11 +31,11 @@ impl ServiceEnclave { .is_err() { error!("Cannot enable backtrace"); - return Err(anyhow!("ecall error")); + bail!("ecall error"); } if !config::is_runtime_config_initialized() { error!("Runtime config is not initialized"); - return Err(anyhow!("ecall error")); + bail!("ecall error"); } Ok(()) --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
