diff --git a/services/backup/blob_client/src/get_client.rs b/services/backup/blob_client/src/get_client.rs --- a/services/backup/blob_client/src/get_client.rs +++ b/services/backup/blob_client/src/get_client.rs @@ -6,7 +6,7 @@ use proto::GetRequest; use crate::constants::{BLOB_ADDRESS, MPSC_CHANNEL_BUFFER_CAPACITY}; -use crate::tools::{report_error}; +use crate::tools::{check_error, report_error}; use lazy_static::lazy_static; use libc; use libc::c_char; @@ -40,16 +40,6 @@ false } -fn check_error() -> Result<(), String> { - if let Ok(errors) = ERROR_MESSAGES.lock() { - return match errors.is_empty() { - true => Ok(()), - false => Err(errors.join("\n")), - }; - } - Err("could not access error messages".to_string()) -} - pub fn get_client_initialize_cxx( holder_char: *const c_char, ) -> Result<(), String> { @@ -125,7 +115,7 @@ pub fn get_client_blocking_read_cxx() -> Result, String> { let mut response: Option> = None; - check_error()?; + check_error(&ERROR_MESSAGES)?; RUNTIME.block_on(async { if let Ok(mut maybe_client) = CLIENT.lock() { if let Some(mut client) = (*maybe_client).take() { @@ -142,15 +132,15 @@ report_error(&ERROR_MESSAGES, "couldn't access client", Some("get")); } }); - check_error()?; + check_error(&ERROR_MESSAGES)?; let response: Vec = response.unwrap(); Ok(response) } pub fn get_client_terminate_cxx() -> Result<(), String> { - check_error()?; + check_error(&ERROR_MESSAGES)?; if !is_initialized() { - check_error()?; + check_error(&ERROR_MESSAGES)?; return Ok(()); } if let Ok(mut maybe_client) = CLIENT.lock() { @@ -175,6 +165,6 @@ !is_initialized(), "client transmitter handler released properly" ); - check_error()?; + check_error(&ERROR_MESSAGES)?; Ok(()) } diff --git a/services/backup/blob_client/src/put_client.rs b/services/backup/blob_client/src/put_client.rs --- a/services/backup/blob_client/src/put_client.rs +++ b/services/backup/blob_client/src/put_client.rs @@ -9,7 +9,7 @@ use proto::PutResponse; use crate::constants::{BLOB_ADDRESS, MPSC_CHANNEL_BUFFER_CAPACITY}; -use crate::tools::report_error; +use crate::tools::{report_error, check_error}; use lazy_static::lazy_static; use libc; use libc::c_char; @@ -52,16 +52,6 @@ false } -fn check_error() -> Result<(), String> { - if let Ok(errors) = ERROR_MESSAGES.lock() { - return match errors.is_empty() { - true => Ok(()), - false => Err(errors.join("\n")), - }; - } - Err("could not access error messages".to_string()) -} - pub fn put_client_initialize_cxx() -> Result<(), String> { if is_initialized() { put_client_terminate_cxx()?; @@ -192,7 +182,7 @@ pub fn put_client_blocking_read_cxx() -> Result { let mut response: Option = None; - check_error()?; + check_error(&ERROR_MESSAGES)?; RUNTIME.block_on(async { if let Ok(mut maybe_client) = CLIENT.lock() { if let Some(mut client) = (*maybe_client).take() { @@ -213,7 +203,7 @@ report_error(&ERROR_MESSAGES, "couldn't access client", Some("put")); } }); - check_error()?; + check_error(&ERROR_MESSAGES)?; response.ok_or("response not received properly".to_string()) } @@ -227,7 +217,7 @@ field_index: usize, data: *const c_char, ) -> Result<(), String> { - check_error()?; + check_error(&ERROR_MESSAGES)?; let data_c_str: &CStr = unsafe { CStr::from_ptr(data) }; let data_bytes: Vec = data_c_str.to_bytes().to_vec(); @@ -261,9 +251,9 @@ } pub fn put_client_terminate_cxx() -> Result<(), String> { - check_error()?; + check_error(&ERROR_MESSAGES)?; if !is_initialized() { - check_error()?; + check_error(&ERROR_MESSAGES)?; return Ok(()); } @@ -290,6 +280,6 @@ !is_initialized(), "client transmitter handler released properly" ); - check_error()?; + check_error(&ERROR_MESSAGES)?; Ok(()) } diff --git a/services/backup/blob_client/src/tools.rs b/services/backup/blob_client/src/tools.rs --- a/services/backup/blob_client/src/tools.rs +++ b/services/backup/blob_client/src/tools.rs @@ -16,3 +16,13 @@ } error!("could not access error messages"); } + +pub fn check_error(error_messages: &Arc>>) -> Result<(), String> { + if let Ok(errors) = error_messages.lock() { + return match errors.is_empty() { + true => Ok(()), + false => Err(errors.join("\n")), + }; + } + Err("could not access error messages".to_string()) +}