Repository: tokio-rs/prost (language: rust)

Issue:
Consider dropping dependency on `failure` in prost-derive
prost-derive uses `failure` very lightly and the crate has fallen out of favour in the community. Consider moving to `anyhow` (that crate has no dependencies!) or directly to the standard error trait.


Discussion / hints:
Sounds good to me, `prost-derive` definitely doesn't need heavy weight error handling.   I'd be fine with just `Result<_, String>` to be honest.  I'm not going to work on this in the short term, so I'd encourage a PR.

Fix patch:
diff --git a/prost-derive/Cargo.toml b/prost-derive/Cargo.toml
index 87311aebf..4c676b81c 100644
--- a/prost-derive/Cargo.toml
+++ b/prost-derive/Cargo.toml
@@ -14,7 +14,7 @@ edition = "2018"
 proc_macro = true
 
 [dependencies]
-failure = { version = "0.1", default-features = false, features = ["std"] }
+anyhow = "1"
 itertools = "0.8"
 proc-macro2 = "1"
 quote = "1"
diff --git a/prost-derive/src/field/group.rs b/prost-derive/src/field/group.rs
index b0e4f122b..23a82f980 100644
--- a/prost-derive/src/field/group.rs
+++ b/prost-derive/src/field/group.rs
@@ -1,4 +1,4 @@
-use failure::{bail, Error};
+use anyhow::{bail, Error};
 use proc_macro2::TokenStream;
 use quote::{quote, ToTokens};
 use syn::Meta;
diff --git a/prost-derive/src/field/map.rs b/prost-derive/src/field/map.rs
index 2d0300150..0bb4a56e4 100644
--- a/prost-derive/src/field/map.rs
+++ b/prost-derive/src/field/map.rs
@@ -1,4 +1,4 @@
-use failure::{bail, Error};
+use anyhow::{bail, Error};
 use proc_macro2::{Span, TokenStream};
 use quote::quote;
 use syn::{Ident, Lit, Meta, MetaNameValue, NestedMeta};
diff --git a/prost-derive/src/field/message.rs b/prost-derive/src/field/message.rs
index f96f56956..6cdbf10ae 100644
--- a/prost-derive/src/field/message.rs
+++ b/prost-derive/src/field/message.rs
@@ -1,4 +1,4 @@
-use failure::{bail, Error};
+use anyhow::{bail, Error};
 use proc_macro2::TokenStream;
 use quote::{quote, ToTokens};
 use syn::Meta;
diff --git a/prost-derive/src/field/mod.rs b/prost-derive/src/field/mod.rs
index 960f8aaea..14b908ecf 100644
--- a/prost-derive/src/field/mod.rs
+++ b/prost-derive/src/field/mod.rs
@@ -7,7 +7,7 @@ mod scalar;
 use std::fmt;
 use std::slice;
 
-use failure::{bail, Error};
+use anyhow::{bail, Error};
 use proc_macro2::TokenStream;
 use quote::quote;
 use syn::{Attribute, Ident, Lit, LitBool, Meta, MetaList, MetaNameValue, NestedMeta};
diff --git a/prost-derive/src/field/oneof.rs b/prost-derive/src/field/oneof.rs
index 0f378f1c5..36bf877e1 100644
--- a/prost-derive/src/field/oneof.rs
+++ b/prost-derive/src/field/oneof.rs
@@ -1,4 +1,4 @@
-use failure::{bail, Error};
+use anyhow::{bail, Error};
 use proc_macro2::TokenStream;
 use quote::quote;
 use syn::{parse_str, Lit, Meta, MetaNameValue, NestedMeta, Path};
diff --git a/prost-derive/src/field/scalar.rs b/prost-derive/src/field/scalar.rs
index c486a396f..8b8180fde 100644
--- a/prost-derive/src/field/scalar.rs
+++ b/prost-derive/src/field/scalar.rs
@@ -1,7 +1,7 @@
 use std::convert::TryFrom;
 use std::fmt;
 
-use failure::{bail, format_err, Error};
+use anyhow::{anyhow, bail, Error};
 use proc_macro2::{Span, TokenStream};
 use quote::{quote, ToTokens};
 use syn::{
@@ -437,7 +437,7 @@ impl Ty {
 
     pub fn from_str(s: &str) -> Result<Ty, Error> {
         let enumeration_len = "enumeration".len();
-        let error = Err(format_err!("invalid type: {}", s));
+        let error = Err(anyhow!("invalid type: {}", s));
         let ty = match s.trim() {
             "float" => Ty::Float,
             "double" => Ty::Double,
diff --git a/prost-derive/src/lib.rs b/prost-derive/src/lib.rs
index 741a55f91..6364e62e2 100644
--- a/prost-derive/src/lib.rs
+++ b/prost-derive/src/lib.rs
@@ -4,10 +4,10 @@
 
 extern crate proc_macro;
 
-use failure::bail;
+use anyhow::bail;
 use quote::quote;
 
-use failure::Error;
+use anyhow::Error;
 use itertools::Itertools;
 use proc_macro::TokenStream;
 use proc_macro2::Span;
@@ -71,7 +71,7 @@ fn try_message(input: TokenStream) -> Result<TokenStream, Error> {
                 )),
             }
         })
-        .collect::<Result<Vec<(Ident, Field)>, failure::Context<String>>>()?;
+        .collect::<Result<Vec<_>, _>>()?;
 
     // We want Debug to be in declaration order
     let unsorted_fields = fields.clone();


Test patch: