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. --- guide/Cargo.toml | 2 +- guide/src/chapter_01.md | 28 ++++++++++++---------------- 2 files changed, 13 insertions(+), 17 deletions(-) (limited to 'guide') diff --git a/guide/Cargo.toml b/guide/Cargo.toml index 5f53762b..28e91690 100644 --- a/guide/Cargo.toml +++ b/guide/Cargo.toml @@ -13,4 +13,4 @@ build = "build.rs" [dependencies] sequoia-openpgp = { path = "../openpgp", version = "0.15" } -failure = "0.1.2" +anyhow = "1" diff --git a/guide/src/chapter_01.md b/guide/src/chapter_01.md index b6c05d21..e2c2a88f 100644 --- a/guide/src/chapter_01.md +++ b/guide/src/chapter_01.md @@ -12,7 +12,6 @@ fragments yields the [`openpgp/examples/generate-sign-verify.rs`]. use std::io::{self, Write}; use std::convert::TryInto; -extern crate failure; extern crate sequoia_openpgp as openpgp; use openpgp::cert::prelude::*; use openpgp::serialize::stream::*; @@ -132,10 +131,10 @@ fn main() { # Some(Err(e)) => # return Err(openpgp::Error::from(e).into()), # None => -# return Err(failure::err_msg("No signature")), +# return Err(anyhow::anyhow!("No signature")), # } # }, -# _ => return Err(failure::err_msg( +# _ => return Err(anyhow::anyhow!( # "Unexpected message structure")), # } # } @@ -143,7 +142,7 @@ fn main() { # if good { # Ok(()) // Good signature. # } else { -# Err(failure::err_msg("Signature verification failed")) +# Err(anyhow::anyhow!("Signature verification failed")) # } # } # } @@ -161,7 +160,6 @@ create it: # use std::io::{self, Write}; # use std::convert::TryInto; # -# extern crate failure; # extern crate sequoia_openpgp as openpgp; # use openpgp::cert::prelude::*; # use openpgp::serialize::stream::*; @@ -281,10 +279,10 @@ fn generate() -> openpgp::Result { # Some(Err(e)) => # return Err(openpgp::Error::from(e).into()), # None => -# return Err(failure::err_msg("No signature")), +# return Err(anyhow::anyhow!("No signature")), # } # }, -# _ => return Err(failure::err_msg( +# _ => return Err(anyhow::anyhow!( # "Unexpected message structure")), # } # } @@ -292,7 +290,7 @@ fn generate() -> openpgp::Result { # if good { # Ok(()) // Good signature. # } else { -# Err(failure::err_msg("Signature verification failed")) +# Err(anyhow::anyhow!("Signature verification failed")) # } # } # } @@ -310,7 +308,6 @@ implements [`io::Write`], and we simply write the plaintext to it. # use std::io::{self, Write}; # use std::convert::TryInto; # -# extern crate failure; # extern crate sequoia_openpgp as openpgp; # use openpgp::cert::prelude::*; # use openpgp::serialize::stream::*; @@ -430,10 +427,10 @@ fn sign(policy: &dyn Policy, # Some(Err(e)) => # return Err(openpgp::Error::from(e).into()), # None => -# return Err(failure::err_msg("No signature")), +# return Err(anyhow::anyhow!("No signature")), # } # }, -# _ => return Err(failure::err_msg( +# _ => return Err(anyhow::anyhow!( # "Unexpected message structure")), # } # } @@ -441,7 +438,7 @@ fn sign(policy: &dyn Policy, # if good { # Ok(()) // Good signature. # } else { -# Err(failure::err_msg("Signature verification failed")) +# Err(anyhow::anyhow!("Signature verification failed")) # } # } # } @@ -470,7 +467,6 @@ Verified data can be read from this using [`io::Read`]. # use std::io::{self, Write}; # use std::convert::TryInto; # -# extern crate failure; # extern crate sequoia_openpgp as openpgp; # use openpgp::cert::prelude::*; # use openpgp::serialize::stream::*; @@ -590,10 +586,10 @@ impl<'a> VerificationHelper for Helper<'a> { Some(Err(e)) => return Err(openpgp::Error::from(e).into()), None => - return Err(failure::err_msg("No signature")), + return Err(anyhow::anyhow!("No signature")), } }, - _ => return Err(failure::err_msg( + _ => return Err(anyhow::anyhow!( "Unexpected message structure")), } } @@ -601,7 +597,7 @@ impl<'a> VerificationHelper for Helper<'a> { if good { Ok(()) // Good signature. } else { - Err(failure::err_msg("Signature verification failed")) + Err(anyhow::anyhow!("Signature verification failed")) } } } -- cgit v1.2.3