From 619c697e2cb6204b983af284d528d11f26ea27d8 Mon Sep 17 00:00:00 2001 From: Miroslav Kovar Date: Mon, 5 Dec 2022 13:31:17 +0100 Subject: [PATCH] Remove failure crate from libvcx Signed-off-by: Miroslav Kovar --- Cargo.lock | 1 - agency_client/src/error.rs | 12 +++++++++++- aries_vcx/src/error.rs | 9 +++++++++ aries_vcx/src/indy/signing.rs | 7 +++++-- libvcx/Cargo.toml | 1 - libvcx/src/api_lib/utils/error.rs | 11 ++++++----- 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2e4ef45575..babcebc5f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2018,7 +2018,6 @@ dependencies = [ "cfg-if 1.0.0", "chrono", "env_logger 0.9.3", - "failure", "futures", "lazy_static", "libc", diff --git a/agency_client/src/error.rs b/agency_client/src/error.rs index b7fb223cfe..e4013681b7 100644 --- a/agency_client/src/error.rs +++ b/agency_client/src/error.rs @@ -106,10 +106,20 @@ impl AgencyClientError { { AgencyClientError { msg: msg.to_string(), - kind + kind, + } + } + + pub fn find_root_cause(&self) -> String { + let mut current = self.source(); + while let Some(cause) = current { + if cause.source().is_none() { return cause.to_string() } + current = cause.source(); } + self.to_string() } + pub fn kind(&self) -> AgencyClientErrorKind { self.kind } diff --git a/aries_vcx/src/error.rs b/aries_vcx/src/error.rs index c21c876dcf..12cb71b727 100644 --- a/aries_vcx/src/error.rs +++ b/aries_vcx/src/error.rs @@ -275,6 +275,15 @@ impl VcxError { } } + pub fn find_root_cause(&self) -> String { + let mut current = self.source(); + while let Some(cause) = current { + if cause.source().is_none() { return cause.to_string() } + current = cause.source(); + } + self.to_string() + } + pub fn kind(&self) -> VcxErrorKind { self.kind } diff --git a/aries_vcx/src/indy/signing.rs b/aries_vcx/src/indy/signing.rs index 1f7477771d..dfe2b5da55 100644 --- a/aries_vcx/src/indy/signing.rs +++ b/aries_vcx/src/indy/signing.rs @@ -1,4 +1,4 @@ -use vdrtools::{Locator, KeyInfo}; +use vdrtools::Locator; use vdrtools::WalletHandle; @@ -94,7 +94,10 @@ pub async fn unpack_message(wallet_handle: WalletHandle, msg: &[u8]) -> VcxResul Ok(res) } +#[cfg(feature = "test_utils")] pub async fn create_key(wallet_handle: WalletHandle, seed: Option<&str>) -> VcxResult { + use vdrtools::KeyInfo; + let res = Locator::instance() .crypto_controller .create_key( @@ -106,4 +109,4 @@ pub async fn create_key(wallet_handle: WalletHandle, seed: Option<&str>) -> VcxR ).await?; Ok(res) -} \ No newline at end of file +} diff --git a/libvcx/Cargo.toml b/libvcx/Cargo.toml index f8834c4de4..9f9e28f595 100644 --- a/libvcx/Cargo.toml +++ b/libvcx/Cargo.toml @@ -36,7 +36,6 @@ base64 = "0.10" futures = { version = "0.3", default-features = false } tokio = { version = "1.15.0", features = ["rt-multi-thread"] } uuid = {version = "0.7.1", default-features = false, features = ["v4"]} -failure = "0.1.8" aries-vcx = { path = "../aries_vcx" } [target.'cfg(target_os = "android")'.dependencies] diff --git a/libvcx/src/api_lib/utils/error.rs b/libvcx/src/api_lib/utils/error.rs index 2d9c7594ae..24eab01452 100644 --- a/libvcx/src/api_lib/utils/error.rs +++ b/libvcx/src/api_lib/utils/error.rs @@ -4,7 +4,6 @@ use std::ffi::CString; use std::ptr; use aries_vcx::agency_client::error::AgencyClientError; -use failure::Fail; use libc::c_char; use crate::api_lib::utils::cstring::CStringUtils; @@ -26,8 +25,9 @@ pub fn set_current_error_agency(err: &AgencyClientError) { let error_json = json!({ "error": err.kind().to_string(), "message": err.to_string(), - "cause": ::find_root_cause(err).to_string(), - "backtrace": err.backtrace().map(|bt| bt.to_string()) + "cause": err.find_root_cause(), + // TODO: Put back once https://github.com/rust-lang/rust/issues/99301 is stabilized + // "backtrace": err.backtrace() }) .to_string(); error.replace(Some(CStringUtils::string_to_cstring(error_json))); @@ -42,8 +42,9 @@ pub fn set_current_error_vcx(err: &VcxError) { let error_json = json!({ "error": err.kind().to_string(), "message": err.to_string(), - "cause": ::find_root_cause(err).to_string(), - "backtrace": err.backtrace().map(|bt| bt.to_string()) + "cause": err.find_root_cause(), + // TODO: Put back once https://github.com/rust-lang/rust/issues/99301 is stabilized + // "backtrace": err.backtrace() }) .to_string(); error.replace(Some(CStringUtils::string_to_cstring(error_json)));