From 391a4b92c977cd64dfd131f3e29b0bc8d756d064 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Mon, 9 Mar 2020 11:42:45 +0100 Subject: Switch from failure to anyhow. - Use the anyhow crate instead of failure to implement the dynamic side of our error handling. anyhow::Error derefs to dyn std::error::Error, allowing better interoperability with other stdlib-based error handling libraries. - Fixes #444. --- ffi/Cargo.toml | 2 +- ffi/src/error.rs | 5 ++--- ffi/src/lib.rs | 1 - ffi/src/net.rs | 2 +- ffi/tests/c-tests.rs | 3 +-- 5 files changed, 5 insertions(+), 8 deletions(-) (limited to 'ffi') diff --git a/ffi/Cargo.toml b/ffi/Cargo.toml index aec51a28..7afd7f61 100644 --- a/ffi/Cargo.toml +++ b/ffi/Cargo.toml @@ -27,7 +27,7 @@ sequoia-openpgp = { path = "../openpgp", version = "0.15" } sequoia-core = { path = "../core", version = "0.15" } sequoia-store = { path = "../store", version = "0.15" } sequoia-net = { path = "../net", version = "0.15" } -failure = "0.1.2" +anyhow = "1" lazy_static = "1.0.0" libc = "0.2.33" memsec = "0.5.6" diff --git a/ffi/src/error.rs b/ffi/src/error.rs index 331bad04..26940111 100644 --- a/ffi/src/error.rs +++ b/ffi/src/error.rs @@ -1,6 +1,5 @@ //! Maps various errors to status codes. -use failure; use std::io; extern crate sequoia_openpgp as openpgp; @@ -10,11 +9,11 @@ pub use crate::openpgp::error::Status; pub(crate) use crate::openpgp::error::Error; trait FromSequoiaError<'a> { - fn from_sequoia_error(_: &'a failure::Error) -> Status; + fn from_sequoia_error(_: &'a anyhow::Error) -> Status; } impl<'a> FromSequoiaError<'a> for Status { - fn from_sequoia_error(e: &'a failure::Error) -> Self { + fn from_sequoia_error(e: &'a anyhow::Error) -> Self { if let Some(e) = e.downcast_ref::() { return match e { &core::Error::NetworkPolicyViolation(_) => diff --git a/ffi/src/lib.rs b/ffi/src/lib.rs index 2d081c3e..ab2819ae 100644 --- a/ffi/src/lib.rs +++ b/ffi/src/lib.rs @@ -107,7 +107,6 @@ #![warn(missing_docs)] -extern crate failure; #[macro_use] extern crate lazy_static; extern crate libc; diff --git a/ffi/src/net.rs b/ffi/src/net.rs index ae297d4b..f40de413 100644 --- a/ffi/src/net.rs +++ b/ffi/src/net.rs @@ -90,7 +90,7 @@ fn sq_keyserver_with_cert(ctx: *mut Context, }; let cert = ffi_try!(Certificate::from_der(cert) - .map_err(|e| ::failure::Error::from(e))); + .map_err(|e| ::anyhow::Error::from(e))); ffi_try_box!(KeyServer::with_cert(&ctx.c, &uri, cert)) } diff --git a/ffi/tests/c-tests.rs b/ffi/tests/c-tests.rs index 934bd9be..afe91c2e 100644 --- a/ffi/tests/c-tests.rs +++ b/ffi/tests/c-tests.rs @@ -1,5 +1,4 @@ -extern crate failure; -use failure::{Fallible as Result, ResultExt}; +use anyhow::{Result, Context}; extern crate filetime; use std::cmp::min; -- cgit v1.2.3