summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-06-01 14:24:35 +0200
committerMatthias Beyer <mail@beyermatthias.de>2020-06-01 14:24:35 +0200
commit4404c34d7dbe524584d07069f3b06a081e98d7b1 (patch)
tree71e92a6a395c8ce9ed65aa4fbdfb25090b779bb1
parent6c672556b8a46a87fa32721abf12f811c4f05ff8 (diff)
Fix imag-bin for use of anyhow
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--bin/domain/imag-mail/Cargo.toml2
-rw-r--r--bin/domain/imag-mail/src/config.rs2
-rw-r--r--bin/domain/imag-mail/src/import.rs7
-rw-r--r--bin/domain/imag-mail/src/lib.rs19
-rw-r--r--bin/domain/imag-mail/src/new.rs23
-rw-r--r--bin/domain/imag-mail/src/util.rs2
6 files changed, 26 insertions, 29 deletions
diff --git a/bin/domain/imag-mail/Cargo.toml b/bin/domain/imag-mail/Cargo.toml
index 5cff3bff..4ac38742 100644
--- a/bin/domain/imag-mail/Cargo.toml
+++ b/bin/domain/imag-mail/Cargo.toml
@@ -21,7 +21,7 @@ maintenance = { status = "actively-developed" }
[dependencies]
log = "0.4"
-failure = "0.1"
+anyhow = "1"
resiter = "0.4"
handlebars = "3"
itertools = "0.9"
diff --git a/bin/domain/imag-mail/src/config.rs b/bin/domain/imag-mail/src/config.rs
index 82e84585..fe071e8e 100644
--- a/bin/domain/imag-mail/src/config.rs
+++ b/bin/domain/imag-mail/src/config.rs
@@ -20,7 +20,7 @@
use std::path::PathBuf;
use handlebars::Handlebars;
-use failure::Fallible as Result;
+use anyhow::Result;
use clap::ArgMatches;
use libimagrt::runtime::Runtime;
diff --git a/bin/domain/imag-mail/src/import.rs b/bin/domain/imag-mail/src/import.rs
index 217e6cf7..48bd9567 100644
--- a/bin/domain/imag-mail/src/import.rs
+++ b/bin/domain/imag-mail/src/import.rs
@@ -17,8 +17,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
-use failure::Fallible as Result;
-use failure::err_msg;
+use anyhow::Result;
use libimagrt::runtime::Runtime;
use toml_query::read::TomlValueReadExt;
@@ -30,9 +29,9 @@ use config::MailConfig;
pub fn import(rt: &Runtime) -> Result<()> {
let config = rt.config()
- .ok_or_else(|| err_msg("Configuration missing"))?
+ .ok_or_else(|| anyhow!("Configuration missing"))?
.read_partial::<MailConfig>()?
- .ok_or_else(|| err_msg("Configuration for \"mail\" missing"))?;
+ .ok_or_else(|| anyhow!("Configuration for \"mail\" missing"))?;
let scmd = rt.cli().subcommand_matches("import").unwrap();
let query = scmd.value_of("query").unwrap();
let quick = scmd.is_present("quick");
diff --git a/bin/domain/imag-mail/src/lib.rs b/bin/domain/imag-mail/src/lib.rs
index a892d0b5..701a8070 100644
--- a/bin/domain/imag-mail/src/lib.rs
+++ b/bin/domain/imag-mail/src/lib.rs
@@ -62,9 +62,8 @@ extern crate libimagentryedit;
use std::io::Write;
use std::io::BufRead;
-use failure::Fallible as Result;
-use failure::err_msg;
-use failure::Error;
+use anyhow::Result;
+use anyhow::Error;
use clap::App;
use resiter::AndThen;
use resiter::IterInnerOkOrElse;
@@ -97,7 +96,7 @@ use config::MailConfig;
pub enum ImagMail {}
impl ImagApplication for ImagMail {
fn run(rt: Runtime) -> Result<()> {
- match rt.cli().subcommand_name().ok_or_else(|| err_msg("No subcommand called"))? {
+ match rt.cli().subcommand_name().ok_or_else(|| anyhow!("No subcommand called"))? {
"import" => import::import(&rt),
"list" => list(&rt),
"print-id" => print_id(&rt),
@@ -133,9 +132,9 @@ impl ImagApplication for ImagMail {
fn list(rt: &Runtime) -> Result<()> {
let config = rt.config()
- .ok_or_else(|| err_msg("Configuration missing"))?
+ .ok_or_else(|| anyhow!("Configuration missing"))?
.read_partial::<MailConfig>()?
- .ok_or_else(|| err_msg("Configuration for \"mail\" missing"))?;
+ .ok_or_else(|| anyhow!("Configuration for \"mail\" missing"))?;
debug!("Listing mail");
let scmd = rt.cli().subcommand_matches("list").unwrap();
@@ -216,11 +215,11 @@ fn list(rt: &Runtime) -> Result<()> {
} else {
// use StoreIds to find mails
let iter = rt.ids::<crate::ui::PathProvider>()?
- .ok_or_else(|| err_msg("No ids supplied"))?
+ .ok_or_else(|| anyhow!("No ids supplied"))?
.into_iter()
.map(Ok)
.into_get_iter(rt.store())
- .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
+ .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
.and_then_ok(|m| m.is_mail().map(|b| (b, m)))
.filter_ok(|tpl| tpl.0)
.map_ok(|tpl| tpl.1);
@@ -232,11 +231,11 @@ fn list(rt: &Runtime) -> Result<()> {
fn print_id(rt: &Runtime) -> Result<()> {
rt.ids::<crate::ui::PathProvider>()?
- .ok_or_else(|| err_msg("No ids supplied"))?
+ .ok_or_else(|| anyhow!("No ids supplied"))?
.into_iter()
.map(Ok)
.into_get_iter(rt.store())
- .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
+ .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
.and_then_ok(|fle| {
let id = fle.get_cached_id()?;
writeln!(rt.stdout(), "{}", id)?;
diff --git a/bin/domain/imag-mail/src/new.rs b/bin/domain/imag-mail/src/new.rs
index 66af2d47..0d9b6139 100644
--- a/bin/domain/imag-mail/src/new.rs
+++ b/bin/domain/imag-mail/src/new.rs
@@ -20,9 +20,9 @@
use std::path::PathBuf;
use std::collections::BTreeMap;
-use failure::Fallible as Result;
-use failure::ResultExt;
-use failure::err_msg;
+use anyhow::Result;
+use anyhow::Context;
+use anyhow::Error;
use toml_query::read::TomlValueReadExt;
use clap::ArgMatches;
use resiter::IterInnerOkOrElse;
@@ -33,7 +33,6 @@ use chrono::Local;
use email_format::Email;
use email_format::rfc5322::Parsable;
use handlebars::Handlebars;
-use failure::Error;
use libimagmail::mail::Mail;
use libimagmail::store::MailStore;
@@ -52,9 +51,9 @@ fn sid_value_of(scmd: &ArgMatches, s: &str) -> Option<Result<StoreId>> {
pub fn new(rt: &Runtime) -> Result<()> {
let config = rt.config()
- .ok_or_else(|| err_msg("Configuration missing"))?
+ .ok_or_else(|| anyhow!("Configuration missing"))?
.read_partial::<MailConfig>()?
- .ok_or_else(|| err_msg("Configuration for \"mail\" missing"))?;
+ .ok_or_else(|| anyhow!("Configuration for \"mail\" missing"))?;
let scmd = rt.cli().subcommand_matches("new").unwrap(); // safe by main()
let notmuch_path = config.get_notmuch_database_path_or_cli(rt);
@@ -67,7 +66,7 @@ pub fn new(rt: &Runtime) -> Result<()> {
let to = sid_value_of(&scmd, "to")
.map(|r| r.map(|e| Some(vec![e])))
.unwrap_or_else(|| rt.ids::<crate::ui::PathProvider>())?
- .ok_or_else(|| err_msg("No ids supplied"))?;
+ .ok_or_else(|| anyhow!("No ids supplied"))?;
let subject = scmd.value_of("subject").map(String::from);
let in_reply_to = scmd.value_of("in-reply-to")
@@ -107,9 +106,9 @@ pub fn new(rt: &Runtime) -> Result<()> {
pub fn reply_to(rt: &Runtime) -> Result<()> {
let config = rt.config()
- .ok_or_else(|| err_msg("Configuration missing"))?
+ .ok_or_else(|| anyhow!("Configuration missing"))?
.read_partial::<MailConfig>()?
- .ok_or_else(|| err_msg("Configuration for \"mail\" missing"))?;
+ .ok_or_else(|| anyhow!("Configuration for \"mail\" missing"))?;
let scmd = rt.cli().subcommand_matches("reply-to").unwrap(); // safe by main()
let store = rt.store();
@@ -117,11 +116,11 @@ pub fn reply_to(rt: &Runtime) -> Result<()> {
let in_reply_to = sid_value_of(&scmd, "in-reply-to")
.map(|r| r.map(|e| Some(vec![e])))
.unwrap_or_else(|| rt.ids::<crate::ui::PathProvider>())?
- .ok_or_else(|| err_msg("No ids supplied"))?
+ .ok_or_else(|| anyhow!("No ids supplied"))?
.into_iter()
.map(Ok)
.into_get_iter(rt.store())
- .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
+ .map_inner_ok_or_else(|| anyhow!("Did not find one entry"))
.and_then_ok(|m| m.is_mail().map(|b| (b, m)))
.filter_ok(|tpl| tpl.0)
.map_ok(|tpl| tpl.1);
@@ -225,7 +224,7 @@ fn edit_message_validated(rt: &Runtime, mut msg: String) -> Result<String> {
if remainder.len() != 0 {
let remainder_s = String::from_utf8_lossy(remainder);
- Err(err_msg("Some bytes are not parsed... cannot verify that the mail is correct!"))
+ Err(anyhow!("Some bytes are not parsed... cannot verify that the mail is correct!"))
.context(format!("Parsing: {}", remainder_s))
.context(format!("Parsing email: {}", msg))?
}
diff --git a/bin/domain/imag-mail/src/util.rs b/bin/domain/imag-mail/src/util.rs
index 506bfc7a..71ca1b23 100644
--- a/bin/domain/imag-mail/src/util.rs
+++ b/bin/domain/imag-mail/src/util.rs
@@ -20,7 +20,7 @@
use std::collections::BTreeMap;
use std::io::Write;
-use failure::Fallible as Result;
+use anyhow::Result;
use handlebars::Handlebars;
use libimaginteraction::format::HandlebarsData;