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,8 +9,7 @@ use crate::constants::{BLOB_ADDRESS, MPSC_CHANNEL_BUFFER_CAPACITY}; use crate::tools::{ - c_char_pointer_to_string, c_char_pointer_to_string_new, check_error, - report_error, string_to_c_char_pointer, string_to_c_char_pointer_new, + c_char_pointer_to_string, c_char_pointer_to_string_new, report_error, string_to_c_char_pointer_new, }; use anyhow::bail; use lazy_static::lazy_static; @@ -199,36 +198,24 @@ pub fn put_client_blocking_read_cxx( holder_char: *const c_char, -) -> Result { - let holder = c_char_pointer_to_string(holder_char)?; - check_error(&ERROR_MESSAGES)?; - let response: Option = RUNTIME.block_on(async { +) -> anyhow::Result { + let holder = c_char_pointer_to_string_new(holder_char)?; + Ok(RUNTIME.block_on(async { if let Ok(mut clients) = CLIENTS.lock() { let maybe_client = clients.get_mut(&holder); if let Some(client) = maybe_client { if let Some(data) = client.rx.recv().await { - return Some(data); + return Ok(data); } else { - report_error( - &ERROR_MESSAGES, - "couldn't receive data via client's receiver", - Some("put"), - ); + bail!("couldn't receive data via client's receiver"); } } else { - report_error( - &ERROR_MESSAGES, - "no client detected in blocking read", - Some("put"), - ); + bail!(format!("no client detected for {} in blocking read", holder)); } } else { - report_error(&ERROR_MESSAGES, "couldn't access client", Some("put")); + bail!("couldn't access clients"); } - None - }); - check_error(&ERROR_MESSAGES)?; - response.ok_or("response not received properly".to_string()) + })?) } /** 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 @@ -19,18 +19,6 @@ error!("could not access error messages"); } -pub fn check_error( - error_messages: &Mutex>, -) -> 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 c_char_pointer_to_string( c_char_pointer: *const c_char, ) -> Result { @@ -48,16 +36,6 @@ Ok(holder_cstr.to_str()?.to_owned()) } -pub fn string_to_c_char_pointer( - signs: &String, -) -> Result<*const c_char, String> { - let cstr = CString::new((&signs).as_bytes()); - match cstr { - Ok(result) => Ok(result.as_ptr()), - Err(err) => Err(err.to_string()), - } -} - pub fn string_to_c_char_pointer_new( signs: &String, ) -> anyhow::Result<*const c_char, anyhow::Error> {