diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-03-09 11:42:45 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-03-09 18:09:50 +0100 |
commit | 391a4b92c977cd64dfd131f3e29b0bc8d756d064 (patch) | |
tree | b5b96ff935853cef9ee22e01890c248a791e724e /ipc | |
parent | 58d662c6d37dd1b0dccd4d0ce30290b8ede408e9 (diff) |
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.
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/Cargo.toml | 2 | ||||
-rw-r--r-- | ipc/src/assuan/mod.rs | 10 | ||||
-rw-r--r-- | ipc/src/gnupg.rs | 20 | ||||
-rw-r--r-- | ipc/src/lib.rs | 7 | ||||
-rw-r--r-- | ipc/tests/gpg-agent.rs | 4 |
5 files changed, 21 insertions, 22 deletions
diff --git a/ipc/Cargo.toml b/ipc/Cargo.toml index c38aa7bd..745e4d9d 100644 --- a/ipc/Cargo.toml +++ b/ipc/Cargo.toml @@ -23,8 +23,8 @@ maintenance = { status = "actively-developed" } sequoia-openpgp = { path = "../openpgp", version = "0.15" } sequoia-core = { path = "../core", version = "0.15" } +anyhow = "1" capnp-rpc = "0.10" -failure = "0.1.2" fs2 = "0.4.2" futures = "0.1" lalrpop-util = "0.17" diff --git a/ipc/src/assuan/mod.rs b/ipc/src/assuan/mod.rs index 75e05f6e..4234b00e 100644 --- a/ipc/src/assuan/mod.rs +++ b/ipc/src/assuan/mod.rs @@ -62,7 +62,7 @@ pub struct Client { enum WriteState { Ready(io::WriteHalf<UnixStream>), - Sending(future::FromErr<io::WriteAll<io::WriteHalf<tokio::net::UnixStream>, Vec<u8>>, failure::Error>), + Sending(future::FromErr<io::WriteAll<io::WriteHalf<tokio::net::UnixStream>, Vec<u8>>, anyhow::Error>), Transitioning, Dead, } @@ -70,7 +70,7 @@ enum WriteState { impl Client { /// Connects to the server. pub fn connect<P>(path: P) - -> impl Future<Item = Client, Error = failure::Error> + -> impl Future<Item = Client, Error = anyhow::Error> where P: AsRef<Path> { UnixStream::connect(path).from_err() @@ -197,7 +197,7 @@ impl ConnectionFuture { impl Future for ConnectionFuture { type Item = Client; - type Error = failure::Error; + type Error = anyhow::Error; fn poll(&mut self) -> std::result::Result<Async<Self::Item>, Self::Error> { // Consume the initial message from the server. @@ -227,7 +227,7 @@ impl Future for ConnectionFuture { impl Stream for Client { type Item = Response; - type Error = failure::Error; + type Error = anyhow::Error; /// Attempt to pull out the next value of this stream, returning /// None if the stream is finished. @@ -400,7 +400,7 @@ impl Response { c)?; } } - Err(failure::err_msg( + Err(anyhow::anyhow!( String::from_utf8_lossy(&msg).to_string()).into()) }, } diff --git a/ipc/src/gnupg.rs b/ipc/src/gnupg.rs index ec308ca2..5d6f848d 100644 --- a/ipc/src/gnupg.rs +++ b/ipc/src/gnupg.rs @@ -111,7 +111,7 @@ impl Context { for argument in arguments { gpgconf.arg(argument); } - let output = gpgconf.output().map_err(|e| -> failure::Error { + let output = gpgconf.output().map_err(|e| -> anyhow::Error { Error::GPGConf(e.to_string()).into() })?; @@ -242,7 +242,7 @@ impl DerefMut for Agent { impl Stream for Agent { type Item = assuan::Response; - type Error = failure::Error; + type Error = anyhow::Error; /// Attempt to pull out the next value of this stream, returning /// None if the stream is finished. @@ -263,7 +263,7 @@ impl Agent { /// server is running for the given context, this operation will /// fail. pub fn connect<'c>(ctx: &'c Context) - -> impl Future<Item = Self, Error = failure::Error> + 'c + -> impl Future<Item = Self, Error = anyhow::Error> + 'c { futures::lazy(move || ctx.socket("agent")) .and_then(Self::connect_to) @@ -275,7 +275,7 @@ impl Agent { /// server is running for the given context, this operation will /// fail. pub fn connect_to<P>(path: P) - -> impl Future<Item = Self, Error = failure::Error> + -> impl Future<Item = Self, Error = anyhow::Error> where P: AsRef<Path> { assuan::Client::connect(path) @@ -288,7 +288,7 @@ impl Agent { key: &'a Key<key::PublicParts, R>, algo: HashAlgorithm, digest: &'a [u8]) -> impl Future<Item = crypto::mpis::Signature, - Error = failure::Error> + 'a + Error = anyhow::Error> + 'a where R: key::KeyRole { SigningRequest::new(&mut self.c, key, algo, digest) @@ -300,7 +300,7 @@ impl Agent { key: &'a Key<key::PublicParts, R>, ciphertext: &'a crypto::mpis::Ciphertext) -> impl Future<Item = crypto::SessionKey, - Error = failure::Error> + 'a + Error = anyhow::Error> + 'a where R: key::KeyRole { DecryptionRequest::new(&mut self.c, key, ciphertext) @@ -407,7 +407,7 @@ impl<'a, 'b, 'c, R> Future for SigningRequest<'a, 'b, 'c, R> where R: key::KeyRole { type Item = crypto::mpis::Signature; - type Error = failure::Error; + type Error = anyhow::Error; fn poll(&mut self) -> std::result::Result<Async<Self::Item>, Self::Error> { use self::SigningRequestState::*; @@ -555,7 +555,7 @@ impl<'a, 'b, 'c, R> Future for DecryptionRequest<'a, 'b, 'c, R> where R: key::KeyRole { type Item = crypto::SessionKey; - type Error = failure::Error; + type Error = anyhow::Error; fn poll(&mut self) -> std::result::Result<Async<Self::Item>, Self::Error> { use self::DecryptionRequestState::*; @@ -713,7 +713,7 @@ impl<'a> crypto::Signer for KeyPair<'a> { } fn sign(&mut self, hash_algo: HashAlgorithm, digest: &[u8]) - -> Result<openpgp::crypto::mpis::Signature> + -> openpgp::Result<openpgp::crypto::mpis::Signature> { use crate::openpgp::types::PublicKeyAlgorithm::*; use crate::openpgp::crypto::mpis::PublicKey; @@ -745,7 +745,7 @@ impl<'a> crypto::Decryptor for KeyPair<'a> { fn decrypt(&mut self, ciphertext: &crypto::mpis::Ciphertext, _plaintext_len: Option<usize>) - -> Result<crypto::SessionKey> + -> openpgp::Result<crypto::SessionKey> { use crate::openpgp::crypto::mpis::{PublicKey, Ciphertext}; diff --git a/ipc/src/lib.rs b/ipc/src/lib.rs index 9526c031..c4946816 100644 --- a/ipc/src/lib.rs +++ b/ipc/src/lib.rs @@ -42,7 +42,6 @@ use std::net::{SocketAddr, AddrParseError, TcpStream, TcpListener}; use std::path::PathBuf; extern crate capnp_rpc; -#[macro_use] extern crate failure; extern crate fs2; extern crate futures; extern crate lalrpop_util; @@ -51,7 +50,7 @@ extern crate tokio; extern crate tokio_core; extern crate tokio_io; -use failure::Fallible as Result; +use anyhow::Result; use fs2::FileExt; use futures::{Future, Stream}; @@ -315,7 +314,7 @@ impl Server { if args.len() != 7 || args[1] != "--home" || args[3] != "--lib" || args[5] != "--ephemeral" { - return Err(format_err!( + return Err(anyhow::anyhow!( "Usage: {} --home <HOMEDIR> --lib <LIBDIR> \ --ephemeral true|false", args[0])); } @@ -328,7 +327,7 @@ impl Server { cfg.set_ephemeral(); } } else { - return Err(format_err!( + return Err(anyhow::anyhow!( "Expected 'true' or 'false' for --ephemeral, got: {}", args[6])); } diff --git a/ipc/tests/gpg-agent.rs b/ipc/tests/gpg-agent.rs index 25b8a711..45c532e6 100644 --- a/ipc/tests/gpg-agent.rs +++ b/ipc/tests/gpg-agent.rs @@ -172,7 +172,7 @@ fn sign() { None => (), } }, - _ => return Err(failure::err_msg( + _ => return Err(anyhow::anyhow!( "Unexpected message structure")), } } @@ -180,7 +180,7 @@ fn sign() { if good { Ok(()) // Good signature. } else { - Err(failure::err_msg("Signature verification failed")) + Err(anyhow::anyhow!("Signature verification failed")) } } } |