diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-03-08 12:06:42 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-03-08 12:06:42 +0100 |
commit | cb9f6e7f46eb1a05071947d5f28bb1fe45313734 (patch) | |
tree | 6e5a8e08e5b204f202de335d412de3f69196ce12 | |
parent | 00aa4df88edae1d5eeb3fb365af05f95bd0de3b4 (diff) | |
parent | 666193dfc26181b6606cb85de5389c4ed6ece5eb (diff) | |
download | imag-cb9f6e7f46eb1a05071947d5f28bb1fe45313734.tar.gz imag-cb9f6e7f46eb1a05071947d5f28bb1fe45313734.tar.xz |
274 files changed, 1300 insertions, 1362 deletions
diff --git a/bin/core/imag-annotate/Cargo.toml b/bin/core/imag-annotate/Cargo.toml index 5c5b89da..1550a100 100644 --- a/bin/core/imag-annotate/Cargo.toml +++ b/bin/core/imag-annotate/Cargo.toml @@ -23,8 +23,8 @@ maintenance = { status = "actively-developed" } log = "0.4.6" url = "2" toml = "0.5.1" -toml-query = "0.9.2" -failure = "0.1.5" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } +anyhow = "1" resiter = "0.4.0" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } diff --git a/bin/core/imag-annotate/src/lib.rs b/bin/core/imag-annotate/src/lib.rs index 42cbea67..df0a9374 100644 --- a/bin/core/imag-annotate/src/lib.rs +++ b/bin/core/imag-annotate/src/lib.rs @@ -38,7 +38,7 @@ extern crate clap; #[macro_use] extern crate log; #[macro_use] -extern crate failure; +extern crate anyhow; extern crate toml_query; extern crate resiter; @@ -52,10 +52,10 @@ extern crate libimagentrylink; use std::io::Write; -use failure::Error; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::err_msg; +use anyhow::Error; +use anyhow::Result; +use anyhow::Context; + use resiter::IterInnerOkOrElse; use resiter::AndThen; use resiter::Map; @@ -65,7 +65,7 @@ use clap::App; use libimagentryannotation::annotateable::*; use libimagentryannotation::annotation_fetcher::*; use libimagentryedit::edit::*; -use libimagerror::errors::ErrorMsg as EM; +use libimagerror::errors::Error as EM; use libimagrt::runtime::Runtime; use libimagrt::application::ImagApplication; use libimagstore::store::FileLockEntry; @@ -78,7 +78,7 @@ mod ui; pub enum ImagAnnotate {} impl ImagApplication for ImagAnnotate { fn run(rt: Runtime) -> Result<()> { - match rt.cli().subcommand_name().ok_or_else(|| err_msg("No command called"))? { + match rt.cli().subcommand_name().ok_or_else(|| anyhow!("No command called"))? { "add" => add(&rt), "remove" => remove(&rt), "list" => list(&rt), @@ -87,7 +87,7 @@ impl ImagApplication for ImagAnnotate { if rt.handle_unknown_subcommand("imag-annotation", other, rt.cli())?.success() { Ok(()) } else { - Err(err_msg("Failed to handle unknown subcommand")) + Err(anyhow!("Failed to handle unknown subcommand")) } }, } @@ -115,7 +115,7 @@ fn add(rt: &Runtime) -> Result<()> { let mut ids = rt .ids::<crate::ui::PathProvider>() .context("No StoreId supplied")? - .ok_or_else(|| err_msg("No ids supplied"))? + .ok_or_else(|| anyhow!("No ids supplied"))? .into_iter(); if let Some(first) = ids.next() { @@ -128,7 +128,7 @@ fn add(rt: &Runtime) -> Result<()> { rt.report_touched(&first)?; // report first one first ids.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(|mut entry| entry.add_link(&mut annotation).map(|_| entry)) .map_report_touched(&rt) .map_ok(|_| ()) @@ -141,7 +141,7 @@ fn add(rt: &Runtime) -> Result<()> { { writeln!(rt.stdout(), "Name of the annotation: {}", annotation_id)?; } else { - Err(format_err!("Unnamed annotation: {:?}", annotation.get_location())) + Err(anyhow!("Unnamed annotation: {:?}", annotation.get_location())) .context("This is most likely a BUG, please report!")?; } } @@ -161,7 +161,7 @@ fn remove(rt: &Runtime) -> Result<()> { rt.ids::<crate::ui::PathProvider>() .context("No ids supplied")? - .ok_or_else(|| err_msg("No ids supplied"))? + .ok_or_else(|| anyhow!("No ids supplied"))? .into_iter() .map(|id| { let mut entry = rt.store() @@ -195,7 +195,7 @@ fn list(rt: &Runtime) -> Result<()> { let ids = rt .ids::<crate::ui::PathProvider>() .context("No ids supplied")? - .ok_or_else(|| err_msg("No ids supplied"))?; + .ok_or_else(|| anyhow!("No ids supplied"))?; if ids.is_empty() { ids.into_iter() @@ -206,7 +206,7 @@ fn list(rt: &Runtime) -> Result<()> { .ok_or_else(|| EM::EntryNotFound(lds))? .annotations()? .into_get_iter(rt.store()) - .map(|el| el.and_then(|o| o.ok_or_else(|| format_err!("Cannot find entry")))) + .map(|el| el.and_then(|o| o.ok_or_else(|| anyhow!("Cannot find entry")))) .enumerate() .map(|(i, entry)| entry.and_then(|e| list_annotation(&rt, i, &e, with_text).map(|_| e))) .map_report_touched(&rt) @@ -220,7 +220,7 @@ fn list(rt: &Runtime) -> Result<()> { rt.store() .all_annotations()? .into_get_iter() - .map(|el| el.and_then(|opt| opt.ok_or_else(|| format_err!("Cannot find entry")))) + .map(|el| el.and_then(|opt| opt.ok_or_else(|| anyhow!("Cannot find entry")))) .enumerate() .map(|(i, entry)| entry.and_then(|e| list_annotation(&rt, i, &e, with_text).map(|_| e))) .map_report_touched(&rt) diff --git a/bin/core/imag-annotate/src/ui.rs b/bin/core/imag-annotate/src/ui.rs index e47a1505..a7bd3364 100644 --- a/bin/core/imag-annotate/src/ui.rs +++ b/bin/core/imag-annotate/src/ui.rs @@ -25,7 +25,7 @@ use libimagstore::storeid::StoreId; use libimagstore::storeid::IntoStoreId; use libimagrt::runtime::IdPathProvider; -use failure::Fallible as Result; +use anyhow::Result; pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { app @@ -114,7 +114,7 @@ impl IdPathProvider for PathProvider { ("remove", Some(subm)) => get_id_paths(subm), ("list", Some(subm)) => get_id_paths(subm), (other, _) => { - Err(format_err!("Not a known command: {}", other)) + Err(anyhow!("Not a known command: {}", other)) } } } diff --git a/bin/core/imag-category/Cargo.toml b/bin/core/imag-category/Cargo.toml index 5fb0c0a0..9aabf454 100644 --- a/bin/core/imag-category/Cargo.toml +++ b/bin/core/imag-category/Cargo.toml @@ -22,8 +22,8 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.6" toml = "0.5.1" -toml-query = "0.9.2" -failure = "0.1.5" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } +anyhow = "1" resiter = "0.4.0" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } diff --git a/bin/core/imag-category/src/lib.rs b/bin/core/imag-category/src/lib.rs index c1c2ed73..d6eb18ef 100644 --- a/bin/core/imag-category/src/lib.rs +++ b/bin/core/imag-category/src/lib.rs @@ -38,7 +38,7 @@ extern crate clap; #[macro_use] extern crate log; #[macro_use] -extern crate failure; +extern crate anyhow; extern crate resiter; extern crate libimagentrycategory; @@ -47,7 +47,7 @@ extern crate libimagrt; extern crate libimagstore; extern crate libimaginteraction; -use failure::Fallible as Result; +use anyhow::Result; use resiter::Map; use clap::App; @@ -59,8 +59,8 @@ mod ui; use std::io::Write; -use failure::err_msg; -use failure::Error; + +use anyhow::Error; use resiter::AndThen; use resiter::IterInnerOkOrElse; @@ -76,7 +76,7 @@ use libimagentrycategory::category::Category; pub enum ImagCategory {} impl ImagApplication for ImagCategory { 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"))? { "set" => set(&rt), "get" => get(&rt), "list-category" => list_category(&rt), @@ -88,7 +88,7 @@ impl ImagApplication for ImagCategory { if rt.handle_unknown_subcommand("imag-category", other, rt.cli())?.success() { Ok(()) } else { - Err(err_msg("Failed to handle unknown subcommand")) + Err(anyhow!("Failed to handle unknown subcommand")) } }, } @@ -116,11 +116,11 @@ fn set(rt: &Runtime) -> Result<()> { let scmd = rt.cli().subcommand_matches("set").unwrap(); // safed by main() let name = scmd.value_of("set-name").map(String::from).unwrap(); // safed by clap 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(|mut e| e.set_category_checked(rt.store(), &name).map(|_| e)) .map_report_touched(&rt) .map_ok(|_| ()) @@ -131,11 +131,11 @@ fn get(rt: &Runtime) -> Result<()> { let out = rt.stdout(); let mut outlock = out.lock(); 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")) .map_report_touched(&rt) .and_then_ok(|e| e.get_category()) .and_then_ok(|n| writeln!(outlock, "{}", n).map_err(Error::from)) @@ -156,7 +156,7 @@ fn list_category(rt: &Runtime) -> Result<()> { .map(|entry| writeln!(outlock, "{}", entry?.get_location()).map_err(Error::from)) .collect() } else { - Err(format_err!("No category named '{}'", name)) + Err(anyhow!("No category named '{}'", name)) } } @@ -175,7 +175,7 @@ fn delete_category(rt: &Runtime) -> Result<()> { let name = scmd.value_of("delete-category-name").map(String::from).unwrap(); // safed by clap let ques = format!("Do you really want to delete category '{}' and remove links to all categorized enties?", name); - let mut input = rt.stdin().ok_or_else(|| err_msg("No input stream. Cannot ask for permission"))?; + let mut input = rt.stdin().ok_or_else(|| anyhow!("No input stream. Cannot ask for permission"))?; let mut output = rt.stdout(); let answer = ask_bool(&ques, Some(false), &mut input, &mut output)?; diff --git a/bin/core/imag-category/src/ui.rs b/bin/core/imag-category/src/ui.rs index 6f80539c..a5810c80 100644 --- a/bin/core/imag-category/src/ui.rs +++ b/bin/core/imag-category/src/ui.rs @@ -20,7 +20,7 @@ use std::path::PathBuf; use clap::{Arg, ArgMatches, App, SubCommand}; -use failure::Fallible as Result; +use anyhow::Result; use libimagstore::storeid::StoreId; use libimagstore::storeid::IntoStoreId; @@ -105,7 +105,7 @@ pub struct PathProvider; impl IdPathProvider for PathProvider { fn get_ids(matches: &ArgMatches) -> Result<Option<Vec<StoreId>>> { fn no_ids_error() -> Result<Option<Vec<StoreId>>> { - Err(format_err!("Command does not get IDs as input")) + Err(anyhow!("Command does not get IDs as input")) } fn get_id_paths(field: &str, subm: &ArgMatches) -> Result<Option<Vec<StoreId>>> { @@ -125,7 +125,7 @@ impl IdPathProvider for PathProvider { ("list-category", _) => no_ids_error(), ("set", Some(subm)) => get_id_paths("set-ids", subm), ("get", Some(subm)) => get_id_paths("get-ids", subm), - (other, _) => Err(format_err!("Not a known command: {}", other)), + (other, _) => Err(anyhow!("Not a known command: {}", other)), } } } diff --git a/bin/core/imag-create/Cargo.toml b/bin/core/imag-create/Cargo.toml index fca9dedc..e4ee82ea 100644 --- a/bin/core/imag-create/Cargo.toml +++ b/bin/core/imag-create/Cargo.toml @@ -16,7 +16,7 @@ homepage = "http://imag-pim.org" [dependencies] log = "0.4" -failure = "0.1" +anyhow = "1" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" } diff --git a/bin/core/imag-create/src/lib.rs b/bin/core/imag-create/src/lib.rs index 03004ea4..674f1ef9 100644 --- a/bin/core/imag-create/src/lib.rs +++ b/bin/core/imag-create/src/lib.rs @@ -35,14 +35,14 @@ )] extern crate clap; -extern crate failure; +#[macro_use] extern crate anyhow; extern crate libimagerror; extern crate libimagrt; extern crate libimagstore; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Result; + use clap::App; use libimagrt::runtime::Runtime; @@ -61,7 +61,7 @@ impl ImagApplication for ImagCreate { let force = rt.cli().is_present("force"); let ids = rt.ids::<crate::ui::PathProvider>()? - .ok_or_else(|| err_msg("No ids supplied"))? + .ok_or_else(|| anyhow!("No ids supplied"))? .into_iter() .map(Ok); diff --git a/bin/core/imag-create/src/ui.rs b/bin/core/imag-create/src/ui.rs index b832f17d..8e5cad01 100644 --- a/bin/core/imag-create/src/ui.rs +++ b/bin/core/imag-create/src/ui.rs @@ -20,7 +20,7 @@ use std::path::PathBuf; use clap::{Arg, ArgMatches, App}; -use failure::Fallible as Result; +use anyhow::Result; use libimagstore::storeid::StoreId; use libimagstore::storeid::IntoStoreId; diff --git a/bin/core/imag-diagnostics/Cargo.toml b/bin/core/imag-diagnostics/Cargo.toml index 557e3f7d..2dafe4ba 100644 --- a/bin/core/imag-diagnostics/Cargo.toml +++ b/bin/core/imag-diagnostics/Cargo.toml @@ -16,9 +16,9 @@ homepage = "http://imag-pim.org" [dependencies] log = "0.4.6" toml = "0.5.1" -toml-query = "0.9.2" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } indicatif = "0.14.0" -failure = "0.1.5" +anyhow = "1" resiter = "0.4.0" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } diff --git a/bin/core/imag-diagnostics/src/lib.rs b/bin/core/imag-diagnostics/src/lib.rs index 427abc67..ac7963f9 100644 --- a/bin/core/imag-diagnostics/src/lib.rs +++ b/bin/core/imag-diagnostics/src/lib.rs @@ -38,7 +38,7 @@ extern crate clap; extern crate toml; extern crate toml_query; extern crate indicatif; -extern crate failure; +#[macro_use] extern crate anyhow; extern crate resiter; #[macro_use] extern crate log; @@ -58,8 +58,8 @@ use libimagentrylink::linkable::Linkable; use toml::Value; use toml_query::read::TomlValueReadExt; use indicatif::{ProgressIterator, ProgressBar, ProgressStyle}; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Result; + use clap::App; use resiter::AndThen; use resiter::IterInnerOkOrElse; @@ -132,7 +132,7 @@ impl ImagApplication for ImagDiagnostics { let diags = rt.store() .entries()? .into_get_iter() - .map_inner_ok_or_else(|| err_msg("Unable to get entry")) + .map_inner_ok_or_else(|| anyhow!("Unable to get entry")) .progress_with(progressbar) .and_then_ok(|e| { let diag = Diagnostic::for_entry(&e); @@ -254,11 +254,11 @@ impl ImagApplication for ImagDiagnostics { } fn get_config(rt: &Runtime, s: &'static str) -> Result<Option<String>> { - let cfg = rt.config().ok_or_else(|| err_msg("No configuration"))?; + let cfg = rt.config().ok_or_else(|| anyhow!("No configuration"))?; match cfg.read(s)? { Some(&Value::String(ref s)) => Ok(Some(s.to_owned())), - Some(_) => Err(err_msg("Config type wrong: 'rt.progressbar_style' should be a string")), + Some(_) => Err(anyhow!("Config type wrong: 'rt.progressbar_style' should be a string")), None => Ok(None), } } diff --git a/bin/core/imag-edit/Cargo.toml b/bin/core/imag-edit/Cargo.toml index 2ec48cfc..0ba6f6d0 100644 --- a/bin/core/imag-edit/Cargo.toml +++ b/bin/core/imag-edit/Cargo.toml @@ -23,8 +23,8 @@ maintenance = { status = "actively-developed" } log = "0.4.6" version = "3.0.0" toml = "0.5.1" -toml-query = "0.9.2" -failure = "0.1.5" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } +anyhow = "1" resiter = "0.4.0" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } diff --git a/bin/core/imag-edit/src/lib.rs b/bin/core/imag-edit/src/lib.rs index d86e7b37..29239e38 100644 --- a/bin/core/imag-edit/src/lib.rs +++ b/bin/core/imag-edit/src/lib.rs @@ -36,7 +36,7 @@ extern crate clap; #[macro_use] extern crate log; -extern crate failure; +#[macro_use] extern crate anyhow; extern crate resiter; extern crate libimagentryedit; @@ -52,8 +52,8 @@ use libimagrt::application::ImagApplication; use libimagrt::iter::ReportTouchedResultEntry; use libimagstore::iter::get::StoreIdGetIteratorExtension; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Result; + use resiter::AndThen; use resiter::IterInnerOkOrElse; use clap::App; @@ -71,11 +71,11 @@ impl ImagApplication for ImagEdit { let edit_header_only = rt.cli().is_present("edit-header-only"); 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")) .inspect(|e| debug!("Editing = {:?}", e)) .map_report_touched(&rt) .and_then_ok(|mut entry| { diff --git a/bin/core/imag-edit/src/ui.rs b/bin/core/imag-edit/src/ui.rs index f13b8fc6..5a195a22 100644 --- a/bin/core/imag-edit/src/ui.rs +++ b/bin/core/imag-edit/src/ui.rs @@ -20,7 +20,7 @@ use std::path::PathBuf; use clap::{Arg, ArgMatches, App}; -use failure::Fallible as Result; +use anyhow::Result; use libimagstore::storeid::IntoStoreId; use libimagstore::storeid::StoreId; diff --git a/bin/core/imag-git/Cargo.toml b/bin/core/imag-git/Cargo.toml index 168e04ce..fb0c04de 100644 --- a/bin/core/imag-git/Cargo.toml +++ b/bin/core/imag-git/Cargo.toml @@ -22,8 +22,8 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.6" toml = "0.5.1" -toml-query = "0.9.2" -failure = "0.1.5" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } +anyhow = "1" libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" } libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } diff --git a/bin/core/imag-git/src/lib.rs b/bin/core/imag-git/src/lib.rs index d839f986..94003d91 100644 --- a/bin/core/imag-git/src/lib.rs +++ b/bin/core/imag-git/src/lib.rs @@ -38,7 +38,7 @@ extern crate clap; #[macro_use] extern crate log; extern crate toml; extern crate toml_query; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate libimagrt; extern crate libimagerror; @@ -49,9 +49,9 @@ use std::process::Command; use toml::Value; use toml_query::read::TomlValueReadExt; use clap::App; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::err_msg; +use anyhow::Result; +use anyhow::Context; + use libimagrt::runtime::Runtime; use libimagrt::application::ImagApplication; @@ -67,18 +67,18 @@ impl ImagApplication for ImagGit { fn run(rt: Runtime) -> Result<()> { let execute_in_store = rt .config() - .ok_or_else(|| err_msg("No configuration. Please use git yourself, not via imag-git")) + .ok_or_else(|| anyhow!("No configuration. Please use git yourself, not via imag-git")) .context("Won't continue without configuration.") ? .read("git.execute_in_store") .context("Failed to read config setting 'git.execute_in_store'") ? - .ok_or_else(|| err_msg("Missing config setting 'git.execute_in_store'")) + .ok_or_else(|| anyhow!("Missing config setting 'git.execute_in_store'")) ?; let execute_in_store = match *execute_in_store { Value::Boolean(b) => Ok(b), - _ => Err(err_msg("Type error: 'git.execute_in_store' is not a boolean!")), + _ => Err(anyhow!("Type error: 'git.execute_in_store' is not a boolean!")), }?; let execpath = if execute_in_store { @@ -87,7 +87,7 @@ impl ImagApplication for ImagGit { rt.rtp().to_str() } .map(String::from) - .ok_or_else(|| format_err!("Cannot parse to string: {:?}", rt.store().path()))?; + .ok_or_else(|| anyhow!("Cannot parse to string: {:?}", rt.store().path()))?; let mut command = Command::new("git"); command @@ -122,7 +122,7 @@ impl ImagApplication for ImagGit { Ok(exit_status) => { if !exit_status.success() { debug!("git exited with non-zero exit code: {:?}", exit_status); - Err(format_err!("git exited with non-zero exit code: {:?}", exit_status)) + Err(anyhow!("git exited with non-zero exit code: {:?}", exit_status)) } else { debug!("Successful exit!"); Ok(()) @@ -132,9 +132,9 @@ impl ImagApplication for ImagGit { Err(e) => { debug!("Error calling git"); Err(match e.kind() { - ErrorKind::NotFound => err_msg("Cannot find 'git' executable"), - ErrorKind::PermissionDenied => err_msg("No permission to execute: 'git'"), - _ => format_err!("Error spawning: {:?}", e), + ErrorKind::NotFound => anyhow!("Cannot find 'git' executable"), + ErrorKind::PermissionDenied => anyhow!("No permission to execute: 'git'"), + _ => anyhow!("Error spawning: {:?}", e), }) } } diff --git a/bin/core/imag-gps/Cargo.toml b/bin/core/imag-gps/Cargo.toml index 5c197e7d..c831f292 100644 --- a/bin/core/imag-gps/Cargo.toml +++ b/bin/core/imag-gps/Cargo.toml @@ -23,8 +23,8 @@ maintenance = { status = "actively-developed" } log = "0.4.6" url = "2" toml = "0.5.1" -toml-query = "0.9.2" -failure = "0.1.5" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } +anyhow = "1" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" } diff --git a/bin/core/imag-gps/src/lib.rs b/bin/core/imag-gps/src/lib.rs index 3cb2deff..594f5926 100644 --- a/bin/core/imag-gps/src/lib.rs +++ b/bin/core/imag-gps/src/lib.rs @@ -36,7 +36,7 @@ extern crate clap; #[macro_use] extern crate log; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate libimagentrygps; extern crate libimagrt; @@ -47,9 +47,9 @@ extern crate libimagstore; use std::io::Write; use std::str::FromStr; -use failure::Error; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Error; +use anyhow::Result; + use clap::App; use libimagstore::storeid::StoreId; @@ -67,7 +67,7 @@ mod ui; pub enum ImagGps {} impl ImagApplication for ImagGps { 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"))? { "add" => add(&rt), "remove" => remove(&rt), "get" => get(&rt), @@ -79,7 +79,7 @@ impl ImagApplication for ImagGps { { Ok(()) } else { - Err(format_err!("Subcommand failed")) + Err(anyhow!("Subcommand failed")) } } } @@ -105,7 +105,7 @@ impl ImagApplication for ImagGps { fn rt_get_ids(rt: &Runtime) -> Result<Vec<StoreId>> { rt .ids::<crate::ui::PathProvider>()? - .ok_or_else(|| err_msg("No ids supplied")) + .ok_or_else(|| anyhow!("No ids supplied")) } fn add(rt: &Runtime) -> Result<()> { @@ -115,11 +115,11 @@ fn add(rt: &Runtime) -> Result<()> { let ary = value.split('.') .map(|v| {debug!("Parsing = {}", v); v}) .map(FromStr::from_str) - .map(|elem| elem.or_else(|_| Err(err_msg("Error while converting number")))) + .map(|elem| elem.or_else(|_| Err(anyhow!("Error while converting number")))) .collect::<Result<Vec<i64>>>()?; - let degree = ary.get(0).ok_or_else(|| err_msg("Degree missing. This value is required."))?; - let minute = ary.get(1).ok_or_else(|| err_msg("Degree missing. This value is required."))?; + let degree = ary.get(0).ok_or_else(|| anyhow!("Degree missing. This value is required."))?; + let minute = ary.get(1).ok_or_else(|| anyhow!("Degree missing. This value is required."))?; let second = ary.get(2).unwrap_or(&0); Ok((*degree, *minute, *second)) @@ -141,7 +141,7 @@ fn add(rt: &Runtime) -> Result<()> { .map(|id| { rt.store() .get(id.clone())? - .ok_or_else(|| format_err!("No such entry: {}", id))? + .ok_or_else(|| anyhow!("No such entry: {}", id))? .set_coordinates(c.clone())?; rt.report_touched(&id) @@ -162,9 +162,9 @@ fn remove(rt: &Runtime) -> Result<()> { let removed_value : Coordinates = rt .store() .get(id.clone())? - .ok_or_else(|| format_err!("No such entry: {}", id))? + .ok_or_else(|| anyhow!("No such entry: {}", id))? .remove_coordinates()? - .ok_or_else(|| format_err!("Entry had no coordinates: {}", id))??; + .ok_or_else(|| anyhow!("Entry had no coordinates: {}", id))??; if print_removed { writeln!(rt.stdout(), "{}", removed_value)?; @@ -185,11 +185,11 @@ fn get(rt: &Runtime) -> Result<()> { .store() .get(id.clone())? .ok_or_else(|| { // if we have Ok(None) - format_err!("No such entry: {}", id) + anyhow!("No such entry: {}", id) })? .get_coordinates()? .ok_or_else(|| { // if we have Ok(None) - format_err!("Entry has no coordinates: {}", id) + anyhow!("Entry has no coordinates: {}", id) })?; writeln!(stdout, "{}", value)?; diff --git a/bin/core/imag-gps/src/ui.rs b/bin/core/imag-gps/src/ui.rs index f76d71b5..1abc924e 100644 --- a/bin/core/imag-gps/src/ui.rs +++ b/bin/core/imag-gps/src/ui.rs @@ -20,7 +20,7 @@ use std::path::PathBuf; use clap::{Arg, ArgMatches, App, SubCommand}; -use failure::Fallible as Result; +use anyhow::Result; use libimagstore::storeid::IntoStoreId; use libimagstore::storeid::StoreId; @@ -114,7 +114,7 @@ impl IdPathProvider for PathProvider { ("add", Some(subm)) => get_id_paths("entry", subm), ("remove", Some(subm)) => get_id_paths("entry", subm), ("get", Some(subm)) => get_id_paths("get-ids", subm), - (other, _) => Err(format_err!("Not a known command: {}", other)), + (other, _) => Err(anyhow!("Not a known command: {}", other)), } } } diff --git a/bin/core/imag-grep/Cargo.toml b/bin/core/imag-grep/Cargo.toml index 21cfee57..9107a85b 100644 --- a/bin/core/imag-grep/Cargo.toml +++ b/bin/core/imag-grep/Cargo.toml @@ -22,7 +22,7 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.6" regex = "1.1.7" -failure = "0.1.5" +anyhow = "1" resiter = "0.4.0" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } diff --git a/bin/core/imag-grep/src/lib.rs b/bin/core/imag-grep/src/lib.rs index e2c291ef..fa7bbc3a 100644 --- a/bin/core/imag-grep/src/lib.rs +++ b/bin/core/imag-grep/src/lib.rs @@ -35,7 +35,7 @@ )] #[macro_use] extern crate log; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate clap; extern crate regex; extern crate resiter; @@ -48,8 +48,8 @@ use std::io::Write; use regex::Regex; use clap::App; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Result; + use resiter::AndThen; use resiter::IterInnerOkOrElse; @@ -84,13 +84,13 @@ impl ImagApplication for ImagGrep { .value_of("pattern") .map(Regex::new) .unwrap() // ensured by clap - .map_err(|e| format_err!("Regex building error: {:?}", e))?; + .map_err(|e| anyhow!("Regex building error: {:?}", e))?; let overall_count = rt .store() .entries()? .into_get_iter() - .map_inner_ok_or_else(|| err_msg("Entry from entries missing")) + .map_inner_ok_or_else(|| anyhow!("Entry from entries missing")) .and_then_ok(|entry| { if pattern.is_match(entry.get_content()) { debug!("Matched: {}", entry.get_location()); diff --git a/bin/core/imag-header/Cargo.toml b/bin/core/imag-header/Cargo.toml index 24a14756..258baa50 100644 --- a/bin/core/imag-header/Cargo.toml +++ b/bin/core/imag-header/Cargo.toml @@ -23,9 +23,9 @@ maintenance = { status = "actively-developed" } log = "0.4.6" version = "3.0.0" toml = "0.5.1" -toml-query = "0.9.2" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } filters = "0.3.0" -failure = "0.1.5" +anyhow = "1" resiter = "0.4.0" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } diff --git a/bin/core/imag-header/src/lib.rs b/bin/core/imag-header/src/lib.rs index b024ac07..40951d1a 100644 --- a/bin/core/imag-header/src/lib.rs +++ b/bin/core/imag-header/src/lib.rs @@ -34,7 +34,7 @@ extern crate clap; #[macro_use] extern crate log; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate toml; extern crate toml_query; extern crate filters; @@ -53,9 +53,9 @@ use std::string::ToString; use clap::{App, ArgMatches}; use filters::filter::Filter; use toml::Value; -use failure::Error; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Error; +use anyhow::Result; + use resiter::FilterMap; use resiter::AndThen; use resiter::IterInnerOkOrElse; @@ -87,11 +87,11 @@ impl ImagApplication for ImagHeader { 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")); match rt.cli().subcommand() { ("read", Some(mtch)) => read(&rt, mtch, iter), @@ -109,7 +109,7 @@ impl ImagApplication for ImagHeader { { Ok(()) } else { - Err(format_err!("Subcommand failed")) + Err(anyhow!("Subcommand failed")) } }, } @@ -144,7 +144,7 @@ fn read<'a, 'e, I>(rt: &Runtime, mtch: &ArgMatches<'a>, iter: I) -> Result<()> trace!("Processing headers: working on {:?}", entry.get_location()); entry.get_header() .read(header_path)? - .ok_or_else(|| format_err!("Value not present for entry {} at {}", entry.get_location(), header_path)) + .ok_or_else(|| anyhow!("Value not present for entry {} at {}", entry.get_location(), header_path)) .and_then(|value| { trace!("Processing headers: Got value {:?}", value); diff --git a/bin/core/imag-header/src/ui.rs b/bin/core/imag-header/src/ui.rs index c7a41225..4c7edd6a 100644 --- a/bin/core/imag-header/src/ui.rs +++ b/bin/core/imag-header/src/ui.rs @@ -20,7 +20,7 @@ use std::path::PathBuf; use clap::{Arg, ArgMatches, App, SubCommand}; -use failure::Fallible as Result; +use anyhow::Result; use libimagstore::storeid::StoreId; use libimagstore::storeid::IntoStoreId; diff --git a/bin/core/imag-id-in-collection/Cargo.toml b/bin/core/imag-id-in-collection/Cargo.toml index 46e92716..91467e8e 100644 --- a/bin/core/imag-id-in-collection/Cargo.toml +++ b/bin/core/imag-id-in-collection/Cargo.toml @@ -23,8 +23,8 @@ maintenance = { status = "actively-developed" } filters = "0.3.0" log = "0.4.6" toml = "0.5.1" -toml-query = "0.9.2" -failure = "0.1.5" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } +anyhow = "1" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" } diff --git a/bin/core/imag-id-in-collection/src/lib.rs b/bin/core/imag-id-in-collection/src/lib.rs index ff3db38a..43f3799e 100644 --- a/bin/core/imag-id-in-collection/src/lib.rs +++ b/bin/core/imag-id-in-collection/src/lib.rs @@ -39,7 +39,7 @@ extern crate filters; #[macro_use] extern crate log; extern crate toml; extern crate toml_query; -extern crate failure; +#[macro_use] extern crate anyhow; #[cfg(test)] extern crate env_logger; @@ -51,8 +51,8 @@ extern crate libimagrt; use std::io::Write; use filters::filter::Filter; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Result; + use clap::App; use libimagstore::storeid::StoreId; @@ -102,7 +102,7 @@ impl ImagApplication for ImagIdInCollection { trace!("Got output: {:?}", stdout); rt.ids::<crate::ui::PathProvider>()? - .ok_or_else(|| err_msg("No ids supplied"))? + .ok_or_else(|| anyhow!("No ids supplied"))? .iter() .filter(|id| collection_filter.filter(id)) .map(|id| { diff --git a/bin/core/imag-id-in-collection/src/ui.rs b/bin/core/imag-id-in-collection/src/ui.rs index 57e37011..09aa80fd 100644 --- a/bin/core/imag-id-in-collection/src/ui.rs +++ b/bin/core/imag-id-in-collection/src/ui.rs @@ -20,7 +20,7 @@ use std::path::PathBuf; use clap::{Arg, ArgMatches, App}; -use failure::Fallible as Result; +use anyhow::Result; use libimagstore::storeid::StoreId; use libimagrt::runtime::IdPathProvider; diff --git a/bin/core/imag-ids/Cargo.toml b/bin/core/imag-ids/Cargo.toml index 036f3a06..635be96d 100644 --- a/bin/core/imag-ids/Cargo.toml +++ b/bin/core/imag-ids/Cargo.toml @@ -22,8 +22,8 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.6" toml = "0.5.1" -toml-query = "0.9.2" -failure = "0.1.5" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } +anyhow = "1" resiter = "0.4.0" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } diff --git a/bin/core/imag-ids/src/lib.rs b/bin/core/imag-ids/src/lib.rs index 9d716a50..2994fb2e 100644 --- a/bin/core/imag-ids/src/lib.rs +++ b/bin/core/imag-ids/src/lib.rs @@ -38,7 +38,7 @@ extern crate clap; #[macro_use] extern crate log; extern crate toml; extern crate toml_query; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate resiter; #[cfg(test)] @@ -50,8 +50,8 @@ extern crate libimagrt; use std::io::Write; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Result; + use resiter::Map; use resiter::AndThen; use clap::App; @@ -99,7 +99,7 @@ impl ImagApplication for ImagIds { if rt.ids_from_stdin() { debug!("Fetching IDs from stdin..."); let mut 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); diff --git a/bin/core/imag-ids/src/ui.rs b/bin/core/imag-ids/src/ui.rs index 94f966c6..9c8a0379 100644 --- a/bin/core/imag-ids/src/ui.rs +++ b/bin/core/imag-ids/src/ui.rs @@ -18,7 +18,7 @@ // use clap::{Arg, ArgMatches, App}; -use failure::Fallible as Result; +use anyhow::Result; use libimagstore::storeid::StoreId; use libimagrt::runtime::IdPathProvider; @@ -36,6 +36,6 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { pub struct PathProvider; impl IdPathProvider for PathProvider { fn get_ids(_matches: &ArgMatches) -> Result<Option<Vec<StoreId>>> { - Err(format_err!("imag-ids does not get IDs via CLI, only via stdin if applying a filter!")) + Err(anyhow!("imag-ids does not get IDs via CLI, only via stdin if applying a filter!")) } } diff --git a/bin/core/imag-init/Cargo.toml b/bin/core/imag-init/Cargo.toml index cf68ef8c..e82bf024 100644 --- a/bin/core/imag-init/Cargo.toml +++ b/bin/core/imag-init/Cargo.toml @@ -20,7 +20,7 @@ is-it-maintained-open-issues = { repository = "matthiasbeyer/imag" } maintenance = { status = "actively-developed" } [dependencies] -failure = "0.1.5" +anyhow = "1" libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" } diff --git a/bin/core/imag-init/src/bin.rs b/bin/core/imag-init/src/bin.rs index bcb6d974..93cd44f3 100644 --- a/bin/core/imag-init/src/bin.rs +++ b/bin/core/imag-init/src/bin.rs @@ -34,8 +34,8 @@ while_true, )] -extern crate failure; -use failure::Fallible as Result; +extern crate anyhow; +use anyhow::Result; extern crate libimaginitcmd; diff --git a/bin/core/imag-init/src/lib.rs b/bin/core/imag-init/src/lib.rs index c2712956..acb7464d 100644 --- a/bin/core/imag-init/src/lib.rs +++ b/bin/core/imag-init/src/lib.rs @@ -35,7 +35,7 @@ )] extern crate clap; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; #[cfg(test)] extern crate toml; @@ -51,10 +51,10 @@ use std::path::PathBuf; use std::path::Path; use std::process::Command; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; -use failure::err_msg; +use anyhow::Result; +use anyhow::Context; +use anyhow::Error; + use libimagrt::runtime::Runtime; use libimagrt::application::ImagApplication; @@ -120,11 +120,11 @@ pub fn imag_init() -> Result<()> { .map(PathBuf::from) .map(|mut p| { p.push(".imag"); p }) .and_then(|path| if path.exists() { - Err(format_err!("Cannot continue: Path '{}' already exists", path.display())) + Err(anyhow!("Cannot continue: Path '{}' already exists", path.display())) } else { Ok(path) }) - .map_err(|_| err_msg("Failed to retrieve/build path for imag directory."))? + .map_err(|_| anyhow!("Failed to retrieve/build path for imag directory."))? }; { @@ -167,7 +167,7 @@ pub fn imag_init() -> Result<()> { let mut gitignore_path = path.clone(); gitignore_path.push(".gitignore"); gitignore_path.to_str().map(String::from) - }.ok_or_else(|| err_msg("Cannot convert path to string"))?; + }.ok_or_else(|| anyhow!("Cannot convert path to string"))?; OpenOptions::new() .write(true) @@ -181,7 +181,7 @@ pub fn imag_init() -> Result<()> { }) .context("Failed to open new configuration file")?; - let path_str = path.to_str().map(String::from).ok_or_else(|| err_msg("Cannot convert path to string"))?; + let path_str = path.to_str().map(String::from).ok_or_else(|| anyhow!("Cannot convert path to string"))?; let worktree = format!("--work-tree={}", path_str); let gitdir = format!("--git-dir={}/.git", path_str); @@ -197,7 +197,7 @@ pub fn imag_init() -> Result<()> { } else { writeln!(out, "{}", String::from_utf8(output.stderr).expect("No UTF-8 output"))?; if !output.status.success() { - return Err(err_msg("Failed to execute git command")); + return Err(anyhow!("Failed to execute git command")); } } } @@ -214,7 +214,7 @@ pub fn imag_init() -> Result<()> { } else { writeln!(out, "{}", String::from_utf8(output.stderr).expect("No UTF-8 output"))?; if !output.status.success() { - return Err(err_msg("Failed to execute git command")); + return Err(anyhow!("Failed to execute git command")); } } } @@ -230,7 +230,7 @@ pub fn imag_init() -> Result<()> { } else { writeln!(out, "{}", String::from_utf8(output.stderr).expect("No UTF-8 output"))?; if !output.status.success() { - return Err(err_msg("Failed to execute git command")); + return Err(anyhow!("Failed to execute git command")); } } } diff --git a/bin/core/imag-link/Cargo.toml b/bin/core/imag-link/Cargo.toml index 50ef9d95..2b8aad2e 100644 --- a/bin/core/imag-link/Cargo.toml +++ b/bin/core/imag-link/Cargo.toml @@ -23,9 +23,9 @@ maintenance = { status = "actively-developed" } log = "0.4.6" url = "2" toml = "0.5.1" -toml-query = "0.9.2" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } prettytable-rs = "0.8.0" -failure = "0.1.5" +anyhow = "1" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" } diff --git a/bin/core/imag-link/src/lib.rs b/bin/core/imag-link/src/lib.rs index 31ec46c5..d4054429 100644 --- a/bin/core/imag-link/src/lib.rs +++ b/bin/core/imag-link/src/lib.rs @@ -37,7 +37,7 @@ #[macro_use] extern crate log; extern crate clap; extern crate url; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; #[macro_use] extern crate prettytable; #[cfg(test)] extern crate toml; #[cfg(test)] extern crate toml_query; @@ -60,7 +60,7 @@ use std::io::Write; use std::path::PathBuf; -use failure::err_msg; + use libimagentryurl::linker::UrlLinker; use libimagentrylink::linkable::Linkable; @@ -71,7 +71,7 @@ use libimagstore::store::FileLockEntry; use libimagstore::storeid::StoreId; use url::Url; -use failure::Fallible as Result; +use anyhow::Result; use clap::App; mod ui; @@ -98,14 +98,14 @@ impl ImagApplication for ImagLink { if rt.handle_unknown_subcommand("imag-link", other, rt.cli())?.success() { Ok(()) } else { - Err(format_err!("Subcommand failed")) + Err(anyhow!("Subcommand failed")) } }, } } else if let (Some(from), Some(to)) = (rt.cli().value_of("from"), rt.cli().values_of("to")) { link_from_to(&rt, from, to) } else { - Err(err_msg("No commandline call")) + Err(anyhow!("No commandline call")) } } @@ -138,13 +138,13 @@ fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I) -> Result<()> where I: Iterator<Item = &'a str> { let directional = rt.cli().is_present("directional"); - let mut from_entry = get_entry_by_name(rt, from)?.ok_or_else(|| err_msg("No 'from' entry"))?; + let mut from_entry = get_entry_by_name(rt, from)?.ok_or_else(|| anyhow!("No 'from' entry"))?; for entry in to { debug!("Handling 'to' entry: {:?}", entry); if rt.store().get(PathBuf::from(entry))?.is_none() { debug!("Linking externally: {:?} -> {:?}", from, entry); - let url = Url::parse(entry).map_err(|e| format_err!("Error parsing URL: {:?}", e))?; + let url = Url::parse(entry).map_err(|e| anyhow!("Error parsing URL: {:?}", e))?; let iter = from_entry .add_url(rt.store(), url)? @@ -158,13 +158,13 @@ fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I) -> Result<()> let entr_id = StoreId::new(PathBuf::from(entry))?; if from_id == entr_id { - return Err(err_msg("Cannot link entry with itself. Exiting")) + return Err(anyhow!("Cannot link entry with itself. Exiting")) } let mut to_entry = rt .store() .get(entr_id)? - .ok_or_else(|| format_err!("No 'to' entry: {}", entry))?; + .ok_or_else(|| anyhow!("No 'to' entry: {}", entry))?; if directional { from_entry.add_link_to(&mut to_entry)?; @@ -188,11 +188,11 @@ fn remove_linking(rt: &Runtime) -> Result<()> { .value_of("from") .map(PathBuf::from) .and_then(|id| rt.store().get(id).transpose()) - .ok_or_else(|| err_msg("No 'from' entry"))??; + .ok_or_else(|| anyhow!("No 'from' entry"))??; rt .ids::<crate::ui::PathProvider>()? - .ok_or_else(|| err_msg("No ids supplied"))? + .ok_or_else(|| anyhow!("No ids supplied"))? .into_iter() .map(|id| match rt.store().get(id.clone())? { Some(mut to_entry) => { @@ -204,13 +204,13 @@ fn remove_linking(rt: &Runtime) -> Result<()> { // looks like this is not an entry, but a filesystem URI and therefor an // external link...? if id.local().is_file() { - let pb = id.local().to_str().ok_or_else(|| format_err!("Not StoreId and not a Path: {}", id))?; - let url = Url::parse(pb).map_err(|e| format_err!("Error parsing URL: {:?}", e))?; + let pb = id.local().to_str().ok_or_else(|| anyhow!("Not StoreId and not a Path: {}", id))?; + let url = Url::parse(pb).map_err(|e| anyhow!("Error parsing URL: {:?}", e))?; from.remove_url(rt.store(), url)?; info!("Ok: {}", id); Ok(()) } else { - Err(format_err!("Entry not found: {:?}", id)) + Err(anyhow!("Entry not found: {:?}", id)) } } }) @@ -222,12 +222,12 @@ fn remove_linking(rt: &Runtime) -> Result<()> { fn unlink(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(|id| { rt.store() .get(id.clone())? - .ok_or_else(|| format_err!("No entry for {}", id))? + .ok_or_else(|| anyhow!("No entry for {}", id))? .unlink(rt.store())?; rt.report_touched(&id) @@ -247,10 +247,10 @@ fn list_linkings(rt: &Runtime) -> Result<()> { tab.set_titles(row!["#", "Link"]); rt.ids::<crate::ui::PathProvider>()? - .ok_or_else(|| err_msg("No ids supplied"))? + .ok_or_else(|| anyhow!("No ids supplied"))? .into_iter() .map(|id| { - let entry = rt.store().get(id.clone())?.ok_or_else(|| format_err!("Not found: {}", id))?; + let entry = rt.store().get(id.clone())?.ok_or_else(|| anyhow!("Not found: {}", id))?; for (i, link) in entry.links()?.enumerate() { let link = link.to_str()?; @@ -302,8 +302,8 @@ mod tests { use toml::value::Value; use toml_query::read::TomlValueReadExt; - use failure::Fallible as Result; - use failure::Error; + use anyhow::Result; + use anyhow::Error; use libimagrt::runtime::Runtime; use libimagstore::storeid::StoreId; diff --git a/bin/core/imag-link/src/ui.rs b/bin/core/imag-link/src/ui.rs index d6f25c55..90aa2506 100644 --- a/bin/core/imag-link/src/ui.rs +++ b/bin/core/imag-link/src/ui.rs @@ -20,7 +20,7 @@ use std::path::PathBuf; use clap::{Arg, ArgMatches, App, SubCommand}; -use failure::Fallible as Result; +use anyhow::Result; use libimagstore::storeid::StoreId; use libimagstore::storeid::IntoStoreId; diff --git a/bin/core/imag-markdown/Cargo.toml b/bin/core/imag-markdown/Cargo.toml index 22f46c38..eb5615d6 100644 --- a/bin/core/imag-markdown/Cargo.toml +++ b/bin/core/imag-markdown/Cargo.toml @@ -22,7 +22,7 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.6" -failure = "0.1.5" +anyhow = "1" resiter = "0.4.0" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } diff --git a/bin/core/imag-markdown/src/lib.rs b/bin/core/imag-markdown/src/lib.rs index 1a8610b5..38303be6 100644 --- a/bin/core/imag-markdown/src/lib.rs +++ b/bin/core/imag-markdown/src/lib.rs @@ -36,7 +36,7 @@ extern crate clap; #[macro_use] extern crate log; -extern crate failure; +#[macro_use] extern crate anyhow; extern crate resiter; extern crate libimagerror; @@ -45,9 +45,9 @@ extern crate libimagstore; use std::io::Write; -use failure::Error; -use failure::err_msg; -use failure::Fallible as Result; +use anyhow::Error; + +use anyhow::Result; use resiter::AndThen; use resiter::Map; use resiter::IterInnerOkOrElse; @@ -72,11 +72,11 @@ impl ImagApplication for ImagMarkdown { 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("Entry does not exist but is in store. This is a BUG, please report!")); + .map_inner_ok_or_else(|| anyhow!("Entry does not exist but is in store. This is a BUG, please report!")); if only_links { debug!("Printing only links"); diff --git a/bin/core/imag-markdown/src/ui.rs b/bin/core/imag-markdown/src/ui.rs index a7e7b73e..a03f0491 100644 --- a/bin/core/imag-markdown/src/ui.rs +++ b/bin/core/imag-markdown/src/ui.rs @@ -20,7 +20,7 @@ use std::path::PathBuf; use clap::{Arg, ArgMatches, App}; -use failure::Fallible as Result; +use anyhow::Result; use libimagstore::storeid::StoreId; use libimagstore::storeid::IntoStoreId; diff --git a/bin/core/imag-mv/Cargo.toml b/bin/core/imag-mv/Cargo.toml index b8bdd374..9d8e7bf9 100644 --- a/bin/core/imag-mv/Cargo.toml +++ b/bin/core/imag-mv/Cargo.toml @@ -21,7 +21,7 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.6" -failure = "0.1.5" +anyhow = "1" resiter = "0.4.0" libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" } diff --git a/bin/core/imag-mv/src/lib.rs b/bin/core/imag-mv/src/lib.rs index 910eb831..3cc159b0 100644 --- a/bin/core/imag-mv/src/lib.rs +++ b/bin/core/imag-mv/src/lib.rs @@ -35,7 +35,7 @@ )] #[macro_use] extern crate log; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate resiter; extern crate clap; @@ -56,8 +56,8 @@ use libimagstore::store::FileLockEntry; use libimagentrylink::linkable::Linkable; use libimagstore::iter::get::StoreIdGetIteratorExtension; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Result; + use resiter::IterInnerOkOrElse; use clap::App; @@ -86,19 +86,19 @@ impl ImagApplication for ImagMv { // remove links to entry, and re-add them later let mut linked_entries = rt.store() .get(sourcename.clone())? - .ok_or_else(|| format_err!("Entry does not exist: {}", sourcename))? + .ok_or_else(|| anyhow!("Entry does not exist: {}", sourcename))? .links()? .map(|link| link.get_store_id().clone()) .map(Ok) .into_get_iter(rt.store()) - .map_inner_ok_or_else(|| err_msg("Linked entry does not exist")) + .map_inner_ok_or_else(|| anyhow!("Linked entry does not exist")) .collect::<Result<Vec<_>>>()?; { // remove links to linked entries from source let mut entry = rt .store() .get(sourcename.clone())? - .ok_or_else(|| err_msg("Source Entry does not exist"))?; + .ok_or_else(|| anyhow!("Source Entry does not exist"))?; for link in linked_entries.iter_mut() { entry.remove_link(link)?; @@ -143,7 +143,7 @@ impl ImagApplication for ImagMv { fn relink<'a>(store: &'a Store, target: StoreId, linked_entries: &mut Vec<FileLockEntry<'a>>) -> Result<()> { let mut entry = store .get(target)? - .ok_or_else(|| err_msg("Funny things happened: Entry moved to destination did not fail, but entry does not exist"))?; + .ok_or_else(|| anyhow!("Funny things happened: Entry moved to destination did not fail, but entry does not exist"))?; linked_entries .iter_mut() diff --git a/bin/core/imag-ref/Cargo.toml b/bin/core/imag-ref/Cargo.toml index a0223e0c..71d34701 100644 --- a/bin/core/imag-ref/Cargo.toml +++ b/bin/core/imag-ref/Cargo.toml @@ -21,7 +21,7 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.6" -failure = "0.1.5" +anyhow = "1" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" } diff --git a/bin/core/imag-ref/src/lib.rs b/bin/core/imag-ref/src/lib.rs index bc41110f..c517b98c 100644 --- a/bin/core/imag-ref/src/lib.rs +++ b/bin/core/imag-ref/src/lib.rs @@ -36,7 +36,7 @@ #[macro_use] extern crate log; extern crate clap; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate libimagstore; extern crate libimagrt; @@ -49,9 +49,9 @@ mod ui; use std::io::Write; -use failure::Fallible as Result; -use failure::Error; -use failure::err_msg; +use anyhow::Result; +use anyhow::Error; + use clap::App; use libimagrt::application::ImagApplication; @@ -81,7 +81,7 @@ impl ImagApplication for ImagRef { if rt.handle_unknown_subcommand("imag-ref", other, rt.cli())?.success() { Ok(()) } else { - Err(format_err!("Subcommand failed")) + Err(anyhow!("Subcommand failed")) } }, } @@ -115,7 +115,7 @@ fn deref(rt: &Runtime) -> Result<()> { let mut outlock = out.lock(); rt.ids::<::ui::PathProvider>()? - .ok_or_else(|| err_msg("No ids supplied"))? + .ok_or_else(|| anyhow!("No ids supplied"))? .into_iter() .map(|id| { match rt.store().get(id.clone())? { @@ -128,12 +128,12 @@ fn deref(rt: &Runtime) -> Result<()> { r_entry.get_path(&cfg) }? .to_str() - .ok_or_else(|| Error::from(::libimagerror::errors::ErrorMsg::UTF8Error)) + .ok_or_else(|| anyhow!("Path is not valid UTF8")) .and_then(|s| writeln!(outlock, "{}", s).map_err(Error::from))?; rt.report_touched(&id) }, - None => Err(format_err!("No entry for id '{}' found", id)) + None => Err(anyhow!("No entry for id '{}' found", id)) } }) .collect() @@ -144,15 +144,15 @@ fn remove(rt: &Runtime) -> Result<()> { let cmd = rt.cli().subcommand_matches("remove").unwrap(); let yes = cmd.is_present("yes"); - let mut input = rt.stdin().ok_or_else(|| err_msg("No input stream. Cannot ask for permission"))?; + let mut input = rt.stdin().ok_or_else(|| anyhow!("No input stream. Cannot ask for permission"))?; let mut output = rt.stdout(); rt.ids::<::ui::PathProvider>()? - .ok_or_else(|| err_msg("No ids supplied"))? + .ok_or_else(|| anyhow!("No ids supplied"))? .into_iter() .map(|id| { match rt.store().get(id.clone())? { - None => Err(format_err!("No entry for id '{}' found", id)), + None => Err(anyhow!("No entry for id '{}' found", id)), Some(mut entry) => { if yes || ask_bool(&format!("Delete ref from entry '{}'", id), None, &mut input, &mut output)? { entry.as_ref_with_hasher_mut::<DefaultHasher>().remove_ref() @@ -174,7 +174,7 @@ fn list_dead(rt: &Runtime) -> Result<()> { let mut output = rt.stdout(); rt.ids::<crate::ui::PathProvider>()? - .ok_or_else(|| err_msg("No ids supplied"))? + .ok_or_else(|| anyhow!("No ids supplied"))? .into_iter() .map(|id| { match rt.store().get(id.clone())? { @@ -202,7 +202,7 @@ fn list_dead(rt: &Runtime) -> Result<()> { } } - None => Err(format_err!("Does not exist: {}", id.local().display())), + None => Err(anyhow!("Does not exist: {}", id.local().display())), } }) .collect() diff --git a/bin/core/imag-ref/src/ui.rs b/bin/core/imag-ref/src/ui.rs index 2b548074..19bd59b8 100644 --- a/bin/core/imag-ref/src/ui.rs +++ b/bin/core/imag-ref/src/ui.rs @@ -20,7 +20,7 @@ use std::path::PathBuf; use clap::{Arg, App, ArgMatches, SubCommand}; -use failure::Fallible as Result; +use anyhow::Result; use libimagstore::storeid::StoreId; use libimagstore::storeid::IntoStoreId; @@ -148,8 +148,8 @@ impl IdPathProvider for PathProvider { ("deref", Some(subm)) => get_id_paths(subm), ("remove", Some(subm)) => get_id_paths(subm), ("list-dead", Some(subm)) => get_id_paths(subm), - ("create", _) => Err(format_err!("Command does not get IDs as input")), - (other, _) => Err(format_err!("Not a known command: {}", other)), + ("create", _) => Err(anyhow!("Command does not get IDs as input")), + (other, _) => Err(anyhow!("Not a known command: {}", other)), } } } diff --git a/bin/core/imag-store/Cargo.toml b/bin/core/imag-store/Cargo.toml index d7a92de7..ae582e58 100644 --- a/bin/core/imag-store/Cargo.toml +++ b/bin/core/imag-store/Cargo.toml @@ -22,7 +22,7 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.6" toml = "0.5.1" -failure = "0.1.5" +anyhow = "1" resiter = "0.4.0" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore", features = ["verify"] } @@ -39,7 +39,7 @@ features = ["color", "suggestions", "wrap_help"] early-panic = [ "libimagstore/early-panic" ] [dev-dependencies] -toml-query = "0.9.2" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } [dev-dependencies.libimagutil] version = "0.10.0" diff --git a/bin/core/imag-store/src/create.rs b/bin/core/imag-store/src/create.rs index 4d13d444..d916d14d 100644 --- a/bin/core/imag-store/src/create.rs +++ b/bin/core/imag-store/src/create.rs @@ -25,8 +25,8 @@ use std::io::Read; use clap::ArgMatches; use toml::Value; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Result; + use libimagrt::runtime::Runtime; use libimagstore::store::Entry; @@ -88,7 +88,7 @@ fn create_from_cli_spec(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> R fn create_from_source(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> Result<()> { let content = matches .value_of("from-raw") - .ok_or_else(|| err_msg("No Commandline call")) + .ok_or_else(|| anyhow!("No Commandline call")) .map(string_from_raw_src)?; debug!("Content with len = {}", content.len()); diff --git a/bin/core/imag-store/src/delete.rs b/bin/core/imag-store/src/delete.rs index 8609369c..3f92bab4 100644 --- a/bin/core/imag-store/src/delete.rs +++ b/bin/core/imag-store/src/delete.rs @@ -19,7 +19,7 @@ use std::path::PathBuf; -use failure::Fallible as Result; +use anyhow::Result; use libimagrt::runtime::Runtime; use libimagstore::storeid::StoreId; diff --git a/bin/core/imag-store/src/get.rs b/bin/core/imag-store/src/get.rs index c1e4410c..9cfe982e 100644 --- a/bin/core/imag-store/src/get.rs +++ b/bin/core/imag-store/src/get.rs @@ -19,8 +19,8 @@ use std::path::PathBuf; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Result; + use libimagrt::runtime::Runtime; use libimagstore::storeid::StoreId; @@ -36,7 +36,7 @@ pub fn get(rt: &Runtime) -> Result<()> { debug!("path = {:?}", path); match rt.store().get(path.clone())? { - None => Err(err_msg("No entry found")), + None => Err(anyhow!("No entry found")), Some(entry) => { print_entry(rt, scmd, entry)?; rt.report_touched(&path) diff --git a/bin/core/imag-store/src/lib.rs b/bin/core/imag-store/src/lib.rs index 4cdd7936..4b065756 100644 --- a/bin/core/imag-store/src/lib.rs +++ b/bin/core/imag-store/src/lib.rs @@ -39,7 +39,7 @@ extern crate clap; extern crate toml; extern crate resiter; #[cfg(test)] extern crate toml_query; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate libimagrt; extern crate libimagstore; @@ -55,8 +55,8 @@ extern crate libimagutil; use libimagrt::application::ImagApplication; use libimagrt::runtime::Runtime; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Result; + mod create; mod delete; @@ -99,12 +99,12 @@ impl ImagApplication for ImagStore { if rt.handle_unknown_subcommand("imag-store", other, rt.cli())?.success() { Ok(()) } else { - Err(format_err!("Subcommand failed")) + Err(anyhow!("Subcommand failed")) } }, } } else { - Err(err_msg("No command")) + Err(anyhow!("No command")) } } diff --git a/bin/core/imag-store/src/retrieve.rs b/bin/core/imag-store/src/retrieve.rs index 92f7b4e4..61383571 100644 --- a/bin/core/imag-store/src/retrieve.rs +++ b/bin/core/imag-store/src/retrieve.rs @@ -20,7 +20,7 @@ use std::path::PathBuf; use std::io::Write; -use failure::Fallible as Result; +use anyhow::Result; use clap::ArgMatches; use libimagstore::store::FileLockEntry; diff --git a/bin/core/imag-store/src/update.rs b/bin/core/imag-store/src/update.rs index d04f0d2d..1c857d69 100644 --- a/bin/core/imag-store/src/update.rs +++ b/bin/core/imag-store/src/update.rs @@ -20,7 +20,7 @@ use std::ops::DerefMut; use std::path::PathBuf; -use failure::Fallible as Result; +use anyhow::Result; use libimagrt::runtime::Runtime; use libimagstore::storeid::StoreId; diff --git a/bin/core/imag-store/src/verify.rs b/bin/core/imag-store/src/verify.rs index 698c0c07..83498958 100644 --- a/bin/core/imag-store/src/verify.rs +++ b/bin/core/imag-store/src/verify.rs @@ -19,8 +19,8 @@ use std::ops::Deref; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Result; + use resiter::AndThen; use resiter::IterInnerOkOrElse; @@ -36,7 +36,7 @@ pub fn verify(rt: &Runtime) -> Result<()> { .store() .entries()? .into_get_iter() - .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 p = fle.get_location(); let content_len = fle.get_content().len(); @@ -58,7 +58,7 @@ pub fn verify(rt: &Runtime) -> Result<()> { info!("Store seems to be fine"); Ok(()) } else { - Err(err_msg("Store seems to be broken somehow")) + Err(anyhow!("Store seems to be broken somehow")) } } diff --git a/bin/core/imag-tag/Cargo.toml b/bin/core/imag-tag/Cargo.toml index 125ec822..7c0b4a6d 100644 --- a/bin/core/imag-tag/Cargo.toml +++ b/bin/core/imag-tag/Cargo.toml @@ -22,7 +22,7 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.6" toml = "0.5.1" -failure = "0.1.5" +anyhow = "1" resiter = "0.4.0" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } @@ -37,7 +37,7 @@ default-features = false features = ["color", "suggestions", "wrap_help"] [dev-dependencies] -toml-query = "0.9.2" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } env_logger = "0.7" [dev-dependencies.libimagutil] diff --git a/bin/core/imag-tag/src/lib.rs b/bin/core/imag-tag/src/lib.rs index df09ef54..f562c9a2 100644 --- a/bin/core/imag-tag/src/lib.rs +++ b/bin/core/imag-tag/src/lib.rs @@ -39,7 +39,7 @@ extern crate resiter; #[macro_use] extern crate log; #[cfg(test)] extern crate toml; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate libimagstore; extern crate libimagrt; @@ -61,8 +61,8 @@ extern crate env_logger; use std::io::Write; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Result; + use resiter::AndThen; use resiter::Map; use resiter::FilterMap; @@ -119,7 +119,7 @@ impl ImagApplication for ImagTag { iter.filter_map_ok(|id| { match rt.store().get(id.clone()) { Err(e) => Some(Err(e)), - Ok(None) => Some(Err(format_err!("No entry for id {}", id))), + Ok(None) => Some(Err(anyhow!("No entry for id {}", id))), Ok(Some(entry)) => { let entry_tags = match entry.get_tags() { Err(e) => return Some(Err(e)), @@ -158,7 +158,7 @@ impl ImagApplication for ImagTag { iter.filter_map_ok(|id| { match rt.store().get(id.clone()) { Err(e) => Some(Err(e)), - Ok(None) => Some(Err(format_err!("No entry for id {}", id))), + Ok(None) => Some(Err(anyhow!("No entry for id {}", id))), Ok(Some(entry)) => { let entry_tags = match entry.get_tags() { Err(e) => return Some(Err(e)), @@ -197,7 +197,7 @@ impl ImagApplication for ImagTag { if rt.handle_unknown_subcommand("imag-tag", other, rt.cli())?.success() { Ok(()) } else { - Err(format_err!("Subcommand failed")) + Err(anyhow!("Subcommand failed")) } }, } @@ -261,7 +261,7 @@ fn alter(rt: &Runtime, path: StoreId, add: Option<Vec<Tag>>, rem: Option<Vec<Tag } fn list(path: StoreId, rt: &Runtime, has_subcommand: bool) -> Result<()> { - let entry = rt.store().get(path.clone())?.ok_or_else(|| err_msg("No entry found"))?; + let entry = rt.store().get(path.clone())?.ok_or_else(|| anyhow!("No entry found"))?; let (scmd, json_out, line_out, sepp_out, mut comm_out) = if has_subcommand { let scmd = rt.cli().subcommand_matches("list").unwrap(); let json_out = scmd.is_present("json"); @@ -320,7 +320,7 @@ fn get_remove_tags(matches: &ArgMatches) -> Result<Option<Vec<Tag>>> { fn retrieve_tags(m: &ArgMatches, s: &'static str, v: &'static str) -> Result<Option<Vec<Tag>>> { Ok(Some(m .subcommand_matches(s) - .ok_or_else(|| format_err!("Expected subcommand '{}', but was not specified", s))? + .ok_or_else(|| anyhow!("Expected subcommand '{}', but was not specified", s))? .values_of(v) .unwrap() // enforced by clap .map(String::from) @@ -334,8 +334,8 @@ mod tests { use toml::value::Value; use toml_query::read::TomlValueReadExt; - use failure::Fallible as Result; - use failure::Error; + use anyhow::Result; + use anyhow::Error; use libimagrt::runtime::Runtime; use libimagstore::storeid::StoreId; diff --git a/bin/core/imag-tag/src/ui.rs b/bin/core/imag-tag/src/ui.rs index 48de0c32..83f8cbea 100644 --- a/bin/core/imag-tag/src/ui.rs +++ b/bin/core/imag-tag/src/ui.rs @@ -20,7 +20,7 @@ use std::path::PathBuf; use clap::{Arg, ArgMatches, ArgGroup, App, SubCommand}; -use failure::Fallible as Result; +use anyhow::Result; use libimagstore::storeid::StoreId; use libimagstore::storeid::IntoStoreId; diff --git a/bin/core/imag-view/Cargo.toml b/bin/core/imag-view/Cargo.toml index 335b80d1..50e7914c 100644 --- a/bin/core/imag-view/Cargo.toml +++ b/bin/core/imag-view/Cargo.toml @@ -22,10 +22,10 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.6" toml = "0.5.1" -toml-query = "0.9.2" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } handlebars = "2" tempfile = "3.0.9" -failure = "0.1.5" +anyhow = "1" resiter = "0.4.0" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } diff --git a/bin/core/imag-view/src/lib.rs b/bin/core/imag-view/src/lib.rs index 3f30f477..eed3e12a 100644 --- a/bin/core/imag-view/src/lib.rs +++ b/bin/core/imag-view/src/lib.rs @@ -40,7 +40,7 @@ extern crate handlebars; extern crate tempfile; extern crate toml; extern crate toml_query; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate resiter; extern crate libimagentryview; @@ -56,8 +56,8 @@ use std::process::Command; use handlebars::Handlebars; use toml_query::read::TomlValueReadTypeExt; -use failure::err_msg; -use failure::Fallible as Result; + +use anyhow::Result; use resiter::AndThen; use resiter::IterInnerOkOrElse; use clap::App; @@ -83,11 +83,11 @@ impl ImagApplication for ImagView { let hide_content = rt.cli().is_present("not-view-content"); let entries = rt .ids::<::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("Entry not found, please report this as a bug")); + .map_inner_ok_or_else(|| anyhow!("Entry not found, please report this as a bug")); if rt.cli().is_present("in") { let files = entries @@ -102,17 +102,17 @@ impl ImagApplication for ImagView { let viewer = rt .cli() .value_of("in") - .ok_or_else(|| err_msg("No viewer given"))?; + .ok_or_else(|| anyhow!("No viewer given"))?; let config = rt .config() - .ok_or_else(|| err_msg("No configuration, cannot continue"))?; + .ok_or_else(|| anyhow!("No configuration, cannot continue"))?; let query = format!("view.viewers.{}", viewer); let viewer_template = config .read_string(&query)? - .ok_or_else(|| format_err!("Cannot find '{}' in config", query))?; + .ok_or_else(|| anyhow!("Cannot find '{}' in config", query))?; let mut handlebars = Handlebars::new(); handlebars.register_escape_fn(::handlebars::no_escape); @@ -131,7 +131,7 @@ impl ImagApplication for ImagView { let call = handlebars .render("template", &data)?; let mut elems = call.split_whitespace(); - let command_string = elems.next().ok_or_else(|| err_msg("No command"))?; + let command_string = elems.next().ok_or_else(|| anyhow!("No command"))?; let mut cmd = Command::new(command_string); for arg in elems { @@ -147,7 +147,7 @@ impl ImagApplication for ImagView { .status()? .success() { - return Err(err_msg("Failed to execute command")) + return Err(anyhow!("Failed to execute command")) } drop(files); @@ -194,7 +194,7 @@ impl ImagApplication for ImagView { if rt.cli().occurrences_of("autowrap") != 0 { let width = rt.cli().value_of("autowrap").unwrap(); // ensured by clap let width = usize::from_str(width).map_err(|_| { - format_err!("Failed to parse argument to number: autowrap = {:?}", + anyhow!("Failed to parse argument to number: autowrap = {:?}", rt.cli().value_of("autowrap").map(String::from)) })?; @@ -258,7 +258,7 @@ fn create_tempfile_for<'a>(entry: &FileLockEntry<'a>, view_header: bool, hide_co .path() .to_str() .map(String::from) - .ok_or_else(|| err_msg("Cannot build path"))?; + .ok_or_else(|| anyhow!("Cannot build path"))?; Ok((tmpfile, file_path)) } diff --git a/bin/core/imag-view/src/ui.rs b/bin/core/imag-view/src/ui.rs index a2f48360..607ab745 100644 --- a/bin/core/imag-view/src/ui.rs +++ b/bin/core/imag-view/src/ui.rs @@ -20,7 +20,7 @@ use std::path::PathBuf; use clap::{Arg, ArgMatches, App}; -use failure::Fallible as Result; +use anyhow::Result; use libimagstore::storeid::StoreId; use libimagstore::storeid::IntoStoreId; diff --git a/bin/core/imag/Cargo.toml b/bin/core/imag/Cargo.toml index cf22e42c..5d1fa3a3 100644 --- a/bin/core/imag/Cargo.toml +++ b/bin/core/imag/Cargo.toml @@ -60,8 +60,8 @@ maintenance = { status = "actively-developed" } walkdir = "2.2.8" log = "0.4.6" toml = "0.5.1" -toml-query = "0.9.2" -failure = "0.1.5" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } +anyhow = "1" libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } diff --git a/bin/core/imag/src/main.rs b/bin/core/imag/src/main.rs index ae61e985..841c66ad 100644 --- a/bin/core/imag/src/main.rs +++ b/bin/core/imag/src/main.rs @@ -36,7 +36,7 @@ extern crate clap; #[macro_use] extern crate log; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate walkdir; extern crate toml; extern crate toml_query; @@ -56,10 +56,10 @@ use walkdir::WalkDir; use clap::{Arg, ArgMatches, AppSettings, SubCommand}; use toml::Value; use toml_query::read::TomlValueReadExt; -use failure::Error; -use failure::ResultExt; -use failure::err_msg; -use failure::Fallible as Result; +use anyhow::Error; +use anyhow::Context; + +use anyhow::Result; use libimagrt::runtime::Runtime; use libimagrt::spec::CliSpec; @@ -144,9 +144,9 @@ fn main() -> Result<()> { // Initialize the Runtime and build the CLI let appname = ::std::env::current_exe()? .file_name() - .ok_or_else(|| format_err!("Program is not a file. This is a BUG, please file me."))? + .ok_or_else(|| anyhow!("Program is not a file. This is a BUG, please file me."))? .to_str() - .ok_or_else(|| format_err!("Program name is not UTF8. Whut?"))? + .ok_or_else(|| anyhow!("Program name is not UTF8. Whut?"))? .to_string(); let version = make_imag_version!(); let about = "imag - the PIM suite for the commandline"; @@ -172,7 +172,7 @@ fn main() -> Result<()> { let long_help = { let mut v = vec![]; app.write_long_help(&mut v)?; - String::from_utf8(v).map_err(|_| err_msg("UTF8 Error"))? + String::from_utf8(v).map_err(|_| anyhow!("UTF8 Error"))? }; let print_help = app.clone().get_matches().subcommand_name().map(|h| h == "help").unwrap_or(false); @@ -260,7 +260,7 @@ fn main() -> Result<()> { { Ok(exit_status) => if !exit_status.success() { debug!("imag-{} exited with non-zero exit code: {:?}", subcommand, exit_status); - Err(format_err!("imag-{} exited with non-zero exit code", subcommand)) + Err(anyhow!("imag-{} exited with non-zero exit code", subcommand)) } else { debug!("Successful exit!"); Ok(()) @@ -288,10 +288,10 @@ fn main() -> Result<()> { } fn fetch_aliases(config: Option<&Value>) -> Result<BTreeMap<String, String>> { - let cfg = config.ok_or_else(|| err_msg("No configuration found"))?; + let cfg = config.ok_or_else(|| anyhow!("No configuration found"))?; let value = cfg .read("imag.aliases") - .map_err(|_| err_msg("Reading from config failed"))?; + .map_err(|_| anyhow!("Reading from config failed"))?; match value { None => Ok(BTreeMap::new()), @@ -310,7 +310,7 @@ fn fetch_aliases(config: Option<&Value>) -> Result<BTreeMap<String, String>> { alias_mappings.insert(s.clone(), k.clone()); }, _ => { - let e = format_err!("Not all values are a String in 'imag.aliases.{}'", k); + let e = anyhow!("Not all values are a String in 'imag.aliases.{}'", k); return Err(e); } } @@ -318,7 +318,7 @@ fn fetch_aliases(config: Option<&Value>) -> Result<BTreeMap<String, String>> { }, _ => { - let msg = format_err!("Type Error: 'imag.aliases.{}' is not a table or string", k); + let msg = anyhow!("Type Error: 'imag.aliases.{}' is not a table or string", k); return Err(msg); }, } @@ -327,7 +327,7 @@ fn fetch_aliases(config: Option<&Value>) -> Result<BTreeMap<String, String>> { Ok(alias_mappings) }, - Some(_) => Err(err_msg("Type Error: 'imag.aliases' is not a table")), + Some(_) => Err(anyhow!("Type Error: 'imag.aliases' is not a table")), } } diff --git a/bin/domain/imag-bookmark/Cargo.toml b/bin/domain/imag-bookmark/Cargo.toml index 4462144b..8ab316de 100644 --- a/bin/domain/imag-bookmark/Cargo.toml +++ b/bin/domain/imag-bookmark/Cargo.toml @@ -22,8 +22,8 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.6" toml = "0.5.1" -toml-query = "0.9.2" -failure = "0.1.5" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } +anyhow = "1" resiter = "0.4.0" url = "2" handlebars = "2" diff --git a/bin/domain/imag-bookmark/src/lib.rs b/bin/domain/imag-bookmark/src/lib.rs index 51259481..ad36c80f 100644 --- a/bin/domain/imag-bookmark/src/lib.rs +++ b/bin/domain/imag-bookmark/src/lib.rs @@ -40,7 +40,7 @@ extern crate toml; extern crate url; extern crate uuid; extern crate toml_query; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate resiter; extern crate handlebars; extern crate rayon; @@ -56,9 +56,9 @@ use std::io::Write; use std::collections::BTreeMap; use std::process::Command; -use failure::Error; -use failure::err_msg; -use failure::Fallible as Result; +use anyhow::Error; + +use anyhow::Result; use resiter::AndThen; use resiter::IterInnerOkOrElse; use clap::App; @@ -86,7 +86,7 @@ mod ui; pub enum ImagBookmark {} impl ImagApplication for ImagBookmark { 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"))? { "add" => add(&rt), "open" => open(&rt), "list" => list(&rt), @@ -97,7 +97,7 @@ impl ImagApplication for ImagBookmark { if rt.handle_unknown_subcommand("imag-bookmark", other, rt.cli())?.success() { Ok(()) } else { - Err(err_msg("Failed to handle unknown subcommand")) + Err(anyhow!("Failed to handle unknown subcommand")) } }, } @@ -139,12 +139,12 @@ fn open(rt: &Runtime) -> Result<()> { let open_command = rt.config() .map(|value| { value.read("bookmark.open")? - .ok_or_else(|| err_msg("Configuration missing: 'bookmark.open'"))? + .ok_or_else(|| anyhow!("Configuration missing: 'bookmark.open'"))? .as_str() - .ok_or_else(|| err_msg("Open command should be a string")) + .ok_or_else(|| anyhow!("Open command should be a string")) }) .or_else(|| Ok(scmd.value_of("opencmd")).transpose()) - .unwrap_or_else(|| Err(err_msg("No open command available in config or on commandline")))?; + .unwrap_or_else(|| Err(anyhow!("No open command available in config or on commandline")))?; let hb = { let mut hb = Handlebars::new(); @@ -153,11 +153,11 @@ fn open(rt: &Runtime) -> Result<()> { }; 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")); if scmd.is_present("openparallel") { let links = iter @@ -195,11 +195,11 @@ fn list(rt: &Runtime) -> Result<()> { rt.store() .all_bookmarks()? .into_get_iter() - .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(|entry| { if entry.is_bookmark()? { let url = entry.get_url()? - .ok_or_else(|| format_err!("Failed to retrieve URL for {}", entry.get_location()))?; + .ok_or_else(|| anyhow!("Failed to retrieve URL for {}", entry.get_location()))?; if !rt.output_is_pipe() { writeln!(rt.stdout(), "{}", url)?; } @@ -214,11 +214,11 @@ fn list(rt: &Runtime) -> Result<()> { fn remove(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| { rt.report_touched(fle.get_location()) .map_err(Error::from) @@ -239,12 +239,12 @@ fn find(rt: &Runtime) -> Result<()> { .all_bookmarks()? .into_get_iter() } - .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| { if fle.is_bookmark()? { let url = fle .get_url()? - .ok_or_else(|| format_err!("Failed to retrieve URL for {}", fle.get_location()))?; + .ok_or_else(|| anyhow!("Failed to retrieve URL for {}", fle.get_location()))?; if url.as_str().contains(substr) { if !rt.output_is_pipe() { writeln!(rt.stdout(), "{}", url)?; @@ -262,7 +262,7 @@ fn find(rt: &Runtime) -> Result<()> { fn calculate_command_data<'a>(hb: &Handlebars, entry: &FileLockEntry<'a>, open_command: &str) -> Result<Vec<String>> { let url = entry.get_url()? - .ok_or_else(|| format_err!("Failed to retrieve URL for {}", entry.get_location()))? + .ok_or_else(|| anyhow!("Failed to retrieve URL for {}", entry.get_location()))? .into_string(); let data = { @@ -277,7 +277,7 @@ fn calculate_command_data<'a>(hb: &Handlebars, entry: &FileLockEntry<'a>, open_c .collect::<Vec<String>>(); if command_rendered.len() > 2 { - return Err(format_err!("Command seems not to include URL: '{}'", open_command)); + return Err(anyhow!("Command seems not to include URL: '{}'", open_command)); } Ok(command_rendered.into_iter().map(String::from).collect()) diff --git a/bin/domain/imag-bookmark/src/ui.rs b/bin/domain/imag-bookmark/src/ui.rs index c7c1a0e4..e4645486 100644 --- a/bin/domain/imag-bookmark/src/ui.rs +++ b/bin/domain/imag-bookmark/src/ui.rs @@ -19,7 +19,7 @@ use std::path::PathBuf; -use failure::Fallible as Result; +use anyhow::Result; use clap::{Arg, ArgMatches, App, SubCommand}; use libimagutil::cli_validators::*; @@ -118,7 +118,7 @@ pub struct PathProvider; impl IdPathProvider for PathProvider { fn get_ids(matches: &ArgMatches) -> Result<Option<Vec<StoreId>>> { fn no_ids_error() -> Result<Option<Vec<StoreId>>> { - Err(format_err!("Command does not get IDs as input")) + Err(anyhow!("Command does not get IDs as input")) } fn get_id_paths(field: &str, subm: &ArgMatches) -> Result<Option<Vec<StoreId>>> { @@ -137,7 +137,7 @@ impl IdPathProvider for PathProvider { ("remove", Some(subm)) => get_id_paths("ids", subm), ("list", Some(subm)) => get_id_paths("ids", subm), ("find", Some(subm)) => get_id_paths("ids", subm), - (other, _) => Err(format_err!("Not a known command: {}", other)), + (other, _) => Err(anyhow!("Not a known command: {}", other)), } } } diff --git a/bin/domain/imag-calendar/Cargo.toml b/bin/domain/imag-calendar/Cargo.toml index be384832..62fd9879 100644 --- a/bin/domain/imag-calendar/Cargo.toml +++ b/bin/domain/imag-calendar/Cargo.toml @@ -22,6 +22,7 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4" +anyhow = "1" failure = "0.1" walkdir = "2.2.8" vobject = "0.7" @@ -45,7 +46,8 @@ default-features = false features = ["color", "suggestions", "wrap_help"] [dependencies.toml-query] -version = "0.9.2" +git = "https://github.com/matthiasbeyer/toml-query" +branch = "master" default-features = false features = ["typed"] diff --git a/bin/domain/imag-calendar/src/filters.rs b/bin/domain/imag-calendar/src/filters.rs index 7e452e94..d57d2129 100644 --- a/bin/domain/imag-calendar/src/filters.rs +++ b/bin/domain/imag-calendar/src/filters.rs @@ -18,7 +18,7 @@ // use chrono::NaiveDateTime; -use failure::Fallible as Result; +use anyhow::Result; use vobject::icalendar::Event; use libimagerror::trace::MapErrTrace; @@ -35,7 +35,7 @@ pub fn event_is_before<'a>(event: &Event<'a>, before_spec: &NaiveDateTime) -> bo Ok(result) }) .unwrap_or_else(|| Err({ - format_err!("Entry with UID {} has no end time, cannot determine whether to list it", + anyhow!("Entry with UID {} has no end time, cannot determine whether to list it", uid()) })); @@ -47,7 +47,7 @@ pub fn event_is_before<'a>(event: &Event<'a>, before_spec: &NaiveDateTime) -> bo Ok(result) }) .unwrap_or_else(|| Err({ - format_err!("Entry with UID {} has no timestamp, cannot determine whether to list it", + anyhow!("Entry with UID {} has no timestamp, cannot determine whether to list it", uid()) })); @@ -72,6 +72,6 @@ fn try_to_parse_datetime(s: &str) -> Result<NaiveDateTime> { ]; ::libimagutil::date::try_to_parse_datetime_from_string(s, FORMATS.iter()) - .ok_or_else(|| format_err!("Cannot parse datetime: {}", s)) + .ok_or_else(|| anyhow!("Cannot parse datetime: {}", s)) } diff --git a/bin/domain/imag-calendar/src/lib.rs b/bin/domain/imag-calendar/src/lib.rs index 5c549195..5e0bf058 100644 --- a/bin/domain/imag-calendar/src/lib.rs +++ b/bin/domain/imag-calendar/src/lib.rs @@ -34,7 +34,7 @@ while_true, )] -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; #[macro_use] extern crate log; extern crate clap; extern crate toml_query; @@ -43,6 +43,7 @@ extern crate handlebars; extern crate chrono; extern crate kairos; extern crate resiter; +extern crate failure; extern crate libimagrt; extern crate libimagcalendar; @@ -53,9 +54,9 @@ extern crate libimagutil; use std::path::PathBuf; use std::io::Write; -use failure::Error; -use failure::err_msg; -use failure::Fallible as Result; +use anyhow::Error; + +use anyhow::Result; use toml_query::read::Partial; use toml_query::read::TomlValueReadExt; use walkdir::DirEntry; @@ -82,7 +83,7 @@ mod util; pub enum ImagCalendar {} impl ImagApplication for ImagCalendar { 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(&rt), "list" => list(&rt), "show" => show(&rt), @@ -92,7 +93,7 @@ impl ImagApplication for ImagCalendar { if rt.handle_unknown_subcommand("imag-calendar", other, rt.cli())?.success() { Ok(()) } else { - Err(err_msg("Failed to handle unknown subcommand")) + Err(anyhow!("Failed to handle unknown subcommand")) } }, } @@ -121,14 +122,14 @@ fn import(rt: &Runtime) -> Result<()> { let do_fail = scmd.is_present("import-fail"); let force_override = scmd.is_present("import-force-override"); let ref_config = rt.config() - .ok_or_else(|| format_err!("No configuration, cannot continue!"))? + .ok_or_else(|| anyhow!("No configuration, cannot continue!"))? .read_partial::<libimagentryref::reference::Config>()? - .ok_or_else(|| format_err!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?; + .ok_or_else(|| anyhow!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?; // sanity check debug!("Doing sanity check on config, to see whether the configuration required for importing is there"); if ref_config.get(collection_name).is_none() { - return Err(format_err!("Configuration missing: {}.{}", libimagentryref::reference::Config::LOCATION, collection_name)) + return Err(anyhow!("Configuration missing: {}.{}", libimagentryref::reference::Config::LOCATION, collection_name)) } debug!("Starting import..."); @@ -191,9 +192,9 @@ fn list(rt: &Runtime) -> Result<()> { let do_filter_before = scmd.value_of("list-before"); let do_filter_after = scmd.value_of("list-after"); let ref_config = rt.config() - .ok_or_else(|| format_err!("No configuration, cannot continue!"))? + .ok_or_else(|| anyhow!("No configuration, cannot continue!"))? .read_partial::<libimagentryref::reference::Config>()? - .ok_or_else(|| format_err!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?; + .ok_or_else(|| anyhow!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?; debug!("List format: {:?}", list_format); debug!("Ref config : {:?}", ref_config); @@ -234,13 +235,13 @@ fn list(rt: &Runtime) -> Result<()> { rt.store() .all_events()? .and_then_ok(|sid| rt.store().get(sid)) - .map_inner_ok_or_else(|| err_msg("Missing entrty while calling all_events()")) + .map_inner_ok_or_else(|| anyhow!("Missing entrty while calling all_events()")) .and_then_ok(|ev| ParsedEventFLE::parse(ev, &ref_config)) .and_then_ok(|parsed_entry| { parsed_entry .get_data() .events() - .map_err(|component| format_err!("Failed to parse entry: {}", component.name)) + .map_err(|component| anyhow!("Failed to parse entry: {}", component.name)) .and_then_ok(|event| { event_filter(&event).map(|b| (event, b)) }) @@ -264,9 +265,9 @@ fn list(rt: &Runtime) -> Result<()> { fn show(rt: &Runtime) -> Result<()> { let scmd = rt.cli().subcommand_matches("show").unwrap(); // safe by clap let ref_config = rt.config() - .ok_or_else(|| format_err!("No configuration, cannot continue!"))? + .ok_or_else(|| anyhow!("No configuration, cannot continue!"))? .read_partial::<libimagentryref::reference::Config>()? - .ok_or_else(|| format_err!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?; + .ok_or_else(|| anyhow!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?; let list_format = util::get_event_print_format("calendar.show_format", rt, &scmd)?; @@ -280,14 +281,14 @@ fn show(rt: &Runtime) -> Result<()> { Ok((e, id)) }) .and_then_ok(|tpl| match tpl { - (None, id) => Err(format_err!("Missing entry: {}", id)), + (None, id) => Err(anyhow!("Missing entry: {}", id)), (Some(e), id) => Ok((e, id)), }) .and_then_ok(|(parsed_entry, id)| { parsed_entry .get_data() .events() - .map_err(|component| format_err!("Failed to parse entry: {}", component.name)) + .map_err(|component| anyhow!("Failed to parse entry: {}", component.name)) .filter_ok(|pent| { let relevant = pent.uid().map(|uid| uid.raw().starts_with(id)).unwrap_or(false); debug!("Relevant {} => {}", parsed_entry.get_entry().get_location(), relevant); diff --git a/bin/domain/imag-calendar/src/util.rs b/bin/domain/imag-calendar/src/util.rs index 8dd382d9..1467d310 100644 --- a/bin/domain/imag-calendar/src/util.rs +++ b/bin/domain/imag-calendar/src/util.rs @@ -23,9 +23,10 @@ use clap::ArgMatches; use vobject::icalendar::ICalendar; use vobject::icalendar::Event; use handlebars::Handlebars; -use failure::Fallible as Result; -use failure::Error; -use failure::err_msg; +use anyhow::Result; +use anyhow::Error; +use failure::Fail; + use toml_query::read::TomlValueReadTypeExt; use chrono::NaiveDateTime; @@ -36,7 +37,6 @@ use libimagentryref::reference::fassade::RefFassade; use libimagentryref::reference::Ref; use libimagentryref::reference::Config; use libimagentryref::hasher::default::DefaultHasher; -use libimagerror::trace::MapErrTrace; use crate::libimagcalendar::store::EventStore; #[derive(Debug)] @@ -54,8 +54,8 @@ impl<'a> ParsedEventFLE<'a> { pub fn parse(fle: FileLockEntry<'a>, refconfig: &Config) -> Result<Self> { fle.as_ref_with_hasher::<DefaultHasher>() .get_path(refconfig) - .and_then(|p| ::std::fs::read_to_string(p).map_err(Error::from)) - .and_then(|s| ICalendar::build(&s).map_err(Error::from)) + .and_then(|p| ::std::fs::read_to_string(p).map_err(|e| Error::from(e.compat()))) + .and_then(|s| ICalendar::build(&s).map_err(|e| Error::from(e.compat()))) .map(|cal| ParsedEventFLE { inner: fle, data: cal, @@ -79,9 +79,9 @@ pub fn get_event_print_format(config_value_path: &'static str, rt: &Runtime, scm .map(Ok) .unwrap_or_else(|| { rt.config() - .ok_or_else(|| err_msg("No configuration file"))? + .ok_or_else(|| anyhow!("No configuration file"))? .read_string(config_value_path)? - .ok_or_else(|| err_msg("Configuration 'contact.list_format' does not exist")) + .ok_or_else(|| anyhow!("Configuration 'contact.list_format' does not exist")) }) .and_then(|fmt| { let mut hb = Handlebars::new(); @@ -124,19 +124,19 @@ pub fn build_data_object_for_handlebars<'a>(i: usize, event: &Event<'a>) } pub fn kairos_parse(spec: &str) -> Result<NaiveDateTime> { - match ::kairos::parser::parse(spec).map_err_trace_exit_unwrap() { + match ::kairos::parser::parse(spec).map_err(|e| Error::from(e.compat()))? { ::kairos::parser::Parsed::Iterator(_) => { trace!("before-filter spec resulted in iterator"); - Err(format_err!("Not a moment in time: {}", spec)) + Err(anyhow!("Not a moment in time: {}", spec)) } ::kairos::parser::Parsed::TimeType(tt) => { trace!("before-filter spec resulted in timetype"); tt.calculate() - .map_err_trace_exit_unwrap() + .map_err(|e| Error::from(e.compat()))? .get_moment() .cloned() - .ok_or_else(|| format_err!("Not a moment in time: {}", spec)) + .ok_or_else(|| anyhow!("Not a moment in time: {}", spec)) } } } @@ -151,7 +151,7 @@ pub fn find_event_by_id<'a>(store: &'a Store, id: &str, refconfig: &Config) -> R let sid = sid?; let event = store.get(sid.clone())?.ok_or_else(|| { - format_err!("Cannot get {}, which should be there.", sid) + anyhow!("Cannot get {}, which should be there.", sid) })?; trace!("Checking whether {} is represented by {}", id, event.get_location()); diff --git a/bin/domain/imag-contact/Cargo.toml b/bin/domain/imag-contact/Cargo.toml index da559479..8625bee7 100644 --- a/bin/domain/imag-contact/Cargo.toml +++ b/bin/domain/imag-contact/Cargo.toml @@ -27,7 +27,7 @@ handlebars = "2" walkdir = "2.2.8" uuid = { version = "0.7.4", features = ["v4"] } serde_json = "1.0.39" -failure = "0.1.5" +anyhow = "1" resiter = "0.4" libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" } @@ -45,7 +45,8 @@ default-features = false features = ["color", "suggestions", "wrap_help"] [dependencies.toml-query] -version = "0.9.2" +git = "https://github.com/matthiasbeyer/toml-query" +branch = "master" default-features = false features = ["typed"] diff --git a/bin/domain/imag-contact/src/create.rs b/bin/domain/imag-contact/src/create.rs index 22394f7a..3c8b3f07 100644 --- a/bin/domain/imag-contact/src/create.rs +++ b/bin/domain/imag-contact/src/create.rs @@ -45,10 +45,10 @@ use toml_query::read::TomlValueReadExt; use toml_query::read::Partial; use toml::Value; use uuid::Uuid; -use failure::Error; -use failure::err_msg; -use failure::Fallible as Result; -use failure::ResultExt; +use anyhow::Error; + +use anyhow::Result; +use anyhow::Context; use libimagcontact::store::ContactStore; use libimagrt::runtime::Runtime; @@ -85,15 +85,15 @@ pub fn create(rt: &Runtime) -> Result<()> { let collection_name = String::from(collection_name); let ref_config = rt // TODO: Re-Deserialize to libimagentryref::reference::Config .config() - .ok_or_else(|| err_msg("Configuration missing, cannot continue!"))? + .ok_or_else(|| anyhow!("Configuration missing, cannot continue!"))? .read_partial::<libimagentryref::reference::Config>()? - .ok_or_else(|| format_err!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?; + .ok_or_else(|| anyhow!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?; // TODO: Refactor the above to libimagutil or libimagrt? let (mut dest, location, uuid) : (Box<dyn Write>, Option<PathBuf>, String) = { if let Some(mut fl) = scmd.value_of("file-location").map(PathBuf::from) { let uuid = if fl.is_file() { - return Err(err_msg("File does exist, cannot create/override")) + return Err(anyhow!("File does exist, cannot create/override")) } else if fl.is_dir() { let uuid = Uuid::new_v4().to_hyphenated().to_string(); fl.push(uuid.clone()); @@ -135,7 +135,7 @@ pub fn create(rt: &Runtime) -> Result<()> { None => fl.file_name() .and_then(|fname| fname.to_str()) .map(String::from) - .ok_or_else(|| err_msg("Cannot calculate UUID for vcard"))?, + .ok_or_else(|| anyhow!("Cannot calculate UUID for vcard"))?, }; (Box::new(file), Some(fl), uuid_string) @@ -147,7 +147,7 @@ pub fn create(rt: &Runtime) -> Result<()> { }; let mut input = rt.stdin().ok_or_else(|| { - err_msg("No input stream. Cannot ask for permission") + anyhow!("No input stream. Cannot ask for permission") })?; let mut output = rt.stdout(); @@ -156,7 +156,7 @@ pub fn create(rt: &Runtime) -> Result<()> { ::libimagentryedit::edit::edit_in_tmpfile(&rt, &mut template)?; if template == TEMPLATE || template.is_empty() { - return Err(err_msg("No (changed) content in tempfile. Not doing anything.")) + return Err(anyhow!("No (changed) content in tempfile. Not doing anything.")) } match ::toml::de::from_str(&template) @@ -265,7 +265,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Key 'nickname.[{}].name' missing", i)) + return Err(anyhow!("Key 'nickname.[{}].name' missing", i)) } }, }; @@ -286,7 +286,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Type Error: Expected Array or String at 'nickname'")) + return Err(anyhow!("Type Error: Expected Array or String at 'nickname'")) } }, None => { @@ -326,7 +326,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Key 'phones.[{}].type' missing", i)) + return Err(anyhow!("Key 'phones.[{}].type' missing", i)) } } }; @@ -338,7 +338,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Key 'phones.[{}].number' missing", i)) + return Err(anyhow!("Key 'phones.[{}].number' missing", i)) } } }; @@ -355,7 +355,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Expected Array at 'phones'.")) + return Err(anyhow!("Expected Array at 'phones'.")) } }, None => { @@ -375,7 +375,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Key 'adresses.[{}].type' missing", i)) + return Err(anyhow!("Key 'adresses.[{}].type' missing", i)) } }, Some(p) => p, @@ -410,7 +410,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Type Error: Expected Array at 'addresses'")) + return Err(anyhow!("Type Error: Expected Array at 'addresses'")) } }, None => { @@ -430,7 +430,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Error: 'email.[{}].type' missing", i)) + return Err(anyhow!("Error: 'email.[{}].type' missing", i)) } }, Some(p) => p, @@ -442,7 +442,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Error: 'email.[{}].addr' missing", i)) + return Err(anyhow!("Error: 'email.[{}].addr' missing", i)) } }, Some(p) => p, @@ -460,7 +460,7 @@ fn parse_toml_into_vcard(output: &mut dyn Write, input: &mut dyn Read, toml: Val if ask_continue(input, output)? { return Ok(None) } else { - return Err(format_err!("Type Error: Expected Array at 'email'")) + return Err(anyhow!("Type Error: Expected Array at 'email'")) } }, None => { @@ -505,7 +505,7 @@ fn read_strary_from_toml(toml: &Value, path: &'static str) -> Result<Option<Vec< match *elem { Value::String(ref s) => v.push(s.clone()), _ => { - return Err(format_err!("Type Error: '{}' must be Array<String>", path)) + return Err(anyhow!("Type Error: '{}' must be Array<String>", path)) }, } } @@ -516,7 +516,7 @@ fn read_strary_from_toml(toml: &Value, path: &'static str) -> Result<Option<Vec< warn!("Having String, wanting Array<String> ... going to auto-fix"); Ok(Some(vec![s.clone()])) }, - Ok(Some(_)) => Err(format_err!("Type Error: '{}' must be Array<String>", path)), + Ok(Some(_)) => Err(anyhow!("Type Error: '{}' must be Array<String>", path)), Ok(None) => Ok(None), Err(_) => Ok(None), } @@ -526,11 +526,11 @@ fn read_str_from_toml(toml: &Value, path: &'static str, must_be_there: bool) -> match toml.read(path)? { Some(&Value::String(ref s)) => Ok(Some(s.clone())), Some(_) => { - Err(format_err!("Type Error: '{}' must be String", path)) + Err(anyhow!("Type Error: '{}' must be String", path)) }, None => { if must_be_there { - return Err(format_err!("Expected '{}' to be present, but is not.", path)) + return Err(anyhow!("Expected '{}' to be present, but is not.", path)) } Ok(None) }, diff --git a/bin/domain/imag-contact/src/edit.rs b/bin/domain/imag-contact/src/edit.rs index b276da64..34024949 100644 --- a/bin/domain/imag-contact/src/edit.rs +++ b/bin/domain/imag-contact/src/edit.rs @@ -35,8 +35,8 @@ use std::io::Read; use std::io::Write; -use failure::err_msg; -use failure::Fallible as Result; + +use anyhow::Result; use resiter::Filter; use resiter::Map; use resiter::AndThen; @@ -58,12 +58,12 @@ pub fn edit(rt: &Runtime) -> Result<()> { let retry = !scmd.is_present("fail-on-parse-error"); if rt.output_is_pipe() { - return Err(err_msg("Cannot spawn editor if output is a pipe!")) + return Err(anyhow!("Cannot spawn editor if output is a pipe!")) } let mut output = rt.stdout(); let mut input = rt.stdin().ok_or_else(|| { - err_msg("No input stream. Cannot ask for permission.") + anyhow!("No input stream. Cannot ask for permission.") })?; crate::util::find_contact_by_hash(rt, hash)? @@ -92,13 +92,13 @@ fn edit_contact<'a>(rt: &Runtime, contact: &FileLockEntry<'a>, ref_config: &RefC .get_path(ref_config)?; let success = rt.editor()? - .ok_or_else(|| err_msg("I have no editor configured. Cannot continue!"))? + .ok_or_else(|| anyhow!("I have no editor configured. Cannot continue!"))? .arg(&filepath) .status()? .success(); if !success { - return Err(err_msg("Editor failed!")) + return Err(anyhow!("Editor failed!")) } rt.store() diff --git a/bin/domain/imag-contact/src/lib.rs b/bin/domain/imag-contact/src/lib.rs index dcfaeb26..13f17e0f 100644 --- a/bin/domain/imag-contact/src/lib.rs +++ b/bin/domain/imag-contact/src/lib.rs @@ -43,7 +43,7 @@ extern crate handlebars; extern crate walkdir; extern crate uuid; extern crate serde_json; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate resiter; extern crate libimagcontact; @@ -64,9 +64,9 @@ use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt; use toml_query::read::Partial; use walkdir::WalkDir; -use failure::Error; -use failure::err_msg; -use failure::Fallible as Result; +use anyhow::Error; + +use anyhow::Result; use resiter::AndThen; use resiter::IterInnerOkOrElse; use resiter::Map; @@ -97,7 +97,7 @@ use crate::edit::edit; pub enum ImagContact {} impl ImagApplication for ImagContact { 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"))? { "list" => list(&rt), "import" => import(&rt), "show" => show(&rt), @@ -109,7 +109,7 @@ impl ImagApplication for ImagContact { if rt.handle_unknown_subcommand("imag-contact", other, rt.cli())?.success() { Ok(()) } else { - Err(err_msg("Failed to handle unknown subcommand")) + Err(anyhow!("Failed to handle unknown subcommand")) } }, } @@ -141,7 +141,7 @@ fn list(rt: &Runtime) -> Result<()> { .store() .all_contacts()? .into_get_iter() - .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| { rt.report_touched(fle.get_location())?; Ok(fle) @@ -177,14 +177,14 @@ fn import(rt: &Runtime) -> Result<()> { let collection_name = rt.cli().value_of("contact-ref-collection-name").unwrap(); // default by clap let ref_config = rt.config() - .ok_or_else(|| format_err!("No configuration, cannot continue!"))? + .ok_or_else(|| anyhow!("No configuration, cannot continue!"))? .read_partial::<libimagentryref::reference::Config>()? - .ok_or_else(|| format_err!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?; + .ok_or_else(|| anyhow!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))?; // TODO: Refactor the above to libimagutil or libimagrt? if !path.exists() { - return Err(format_err!("Path does not exist: {}", path.display())) + return Err(anyhow!("Path does not exist: {}", path.display())) } if path.is_file() { @@ -216,7 +216,7 @@ fn import(rt: &Runtime) -> Result<()> { .collect::<Result<Vec<_>>>() .map(|_| ()) } else { - Err(err_msg("Path is neither directory nor file")) + Err(anyhow!("Path is neither directory nor file")) } } @@ -253,7 +253,7 @@ fn show(rt: &Runtime) -> Result<()> { .map(PathBuf::from) .map(StoreId::new) .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")); show_contacts(rt, &show_format, iter) } else { @@ -268,11 +268,11 @@ fn show(rt: &Runtime) -> Result<()> { } } else { 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")); show_contacts(rt, &show_format, iter) } @@ -294,7 +294,7 @@ fn find(rt: &Runtime) -> Result<()> { .store() .all_contacts()? .into_get_iter() - .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(|entry| { let card = entry.deser()?; @@ -384,9 +384,9 @@ fn get_contact_print_format(config_value_path: &'static str, rt: &Runtime, scmd: let fmt = match scmd.value_of("format").map(String::from) { Some(s) => Ok(s), None => rt.config() - .ok_or_else(|| err_msg("No configuration file"))? + .ok_or_else(|| anyhow!("No configuration file"))? .read_string(config_value_path)? - .ok_or_else(|| err_msg("Configuration 'contact.list_format' does not exist")), + .ok_or_else(|| anyhow!("Configuration 'contact.list_format' does not exist")), }?; let mut hb = Handlebars::new(); diff --git a/bin/domain/imag-contact/src/ui.rs b/bin/domain/imag-contact/src/ui.rs index 99cd9704..2d5e1240 100644 --- a/bin/domain/imag-contact/src/ui.rs +++ b/bin/domain/imag-contact/src/ui.rs @@ -20,7 +20,7 @@ use std::path::PathBuf; use clap::{Arg, ArgMatches, App, SubCommand}; -use failure::Fallible as Result; +use anyhow::Result; use libimagstore::storeid::StoreId; use libimagrt::runtime::IdPathProvider; diff --git a/bin/domain/imag-contact/src/util.rs b/bin/domain/imag-contact/src/util.rs index c3d2c1fb..2125753c 100644 --- a/bin/domain/imag-contact/src/util.rs +++ b/bin/domain/imag-contact/src/util.rs @@ -19,8 +19,8 @@ use std::collections::BTreeMap; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Result; + use resiter::IterInnerOkOrElse; use resiter::AndThen; @@ -91,12 +91,12 @@ pub fn find_contact_by_hash<'a, H: AsRef<str>>(rt: &'a Runtime, hash: H) Ok(rt.store() .all_contacts()? .into_get_iter() - .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(move |entry| { let deser = entry.deser()?; let id_starts_with_hash = deser.uid() - .ok_or_else(|| err_msg("Could not get StoreId from Store::all_contacts(). This is a BUG!"))? + .ok_or_else(|| anyhow!("Could not get StoreId from Store::all_contacts(). This is a BUG!"))? .starts_with(hash.as_ref()); if id_starts_with_hash { diff --git a/bin/domain/imag-diary/Cargo.toml b/bin/domain/imag-diary/Cargo.toml index 669c9d31..4d53f523 100644 --- a/bin/domain/imag-diary/Cargo.toml +++ b/bin/domain/imag-diary/Cargo.toml @@ -23,9 +23,9 @@ maintenance = { status = "actively-developed" } chrono = "0.4.7" log = "0.4.6" toml = "0.5.1" -toml-query = "0.9.2" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } itertools = "0.8.0" -failure = "0.1.5" +anyhow = "1" resiter = "0.4.0" option-inspect = "0.1.0" diff --git a/bin/domain/imag-diary/src/create.rs b/bin/domain/imag-diary/src/create.rs index 43b25d6a..8dccbee8 100644 --- a/bin/domain/imag-diary/src/create.rs +++ b/bin/domain/imag-diary/src/create.rs @@ -21,10 +21,10 @@ use clap::ArgMatches; use chrono::NaiveDateTime; use chrono::Local; use chrono::Timelike; -use failure::Error; -use failure::ResultExt; -use failure::err_msg; -use failure::Fallible as Result; +use anyhow::Error; +use anyhow::Context; + +use anyhow::Result; use option_inspect::*; use libimagdiary::diary::Diary; @@ -39,7 +39,7 @@ use crate::util::Timed; pub fn create(rt: &Runtime) -> Result<()> { let diaryname = get_diary_name(rt) - .ok_or_else(|| err_msg("No diary selected. Use either the configuration file or the commandline option"))?; + .ok_or_else(|| anyhow!("No diary selected. Use either the configuration file or the commandline option"))?; let mut entry = create_entry(rt.store(), &diaryname, rt)?; rt.report_touched(entry.get_location())?; @@ -50,7 +50,7 @@ pub fn create(rt: &Runtime) -> Result<()> { Ok(()) } else { debug!("Editing new diary entry"); - entry.edit_content(rt).context(err_msg("Diary edit error")).map_err(Error::from) + entry.edit_content(rt).context(anyhow!("Diary edit error")).map_err(Error::from) } } @@ -67,7 +67,7 @@ fn create_entry<'a>(diary: &'a Store, diaryname: &str, rt: &Runtime) -> Result<F if let Some(timed) = timed { let time = create_id_from_clispec(&create, timed)?; diary.new_entry_at(&diaryname, &time) - .context(err_msg("Store write error")) + .context(anyhow!("Store write error")) .map_err(Error::from) } else { debug!("Creating non-timed entry"); @@ -107,7 +107,7 @@ fn create_id_from_clispec(create: &ArgMatches, timed_type: Timed) -> Result<Naiv .map(|s| { FromStr::from_str(s) .map_err(Error::from) - .context(format_err!("Could not parse minute: '{}'", s)) + .context(anyhow!("Could not parse minute: '{}'", s)) .map_err(Error::from) }) .transpose()? @@ -115,7 +115,7 @@ fn create_id_from_clispec(create: &ArgMatches, timed_type: Timed) -> Result<Naiv ndt.with_minute(min) .ok_or_else(|| { - format_err!("Cannot set {} as minute, would yield invalid time!", min) + anyhow!("Cannot set {} as minute, would yield invalid time!", min) }) .map(|ndt| ndt.with_second(0).unwrap()) // safe because second = 0 is safe }, @@ -127,7 +127,7 @@ fn create_id_from_clispec(create: &ArgMatches, timed_type: Timed) -> Result<Naiv .map(|s| { FromStr::from_str(s) .map_err(Error::from) - .context(format_err!("Could not parse minute: '{}'", s)) + .context(anyhow!("Could not parse minute: '{}'", s)) .map_err(Error::from) }) .transpose()? @@ -139,7 +139,7 @@ fn create_id_from_clispec(create: &ArgMatches, timed_type: Timed) -> Result<Naiv .map(|s| { FromStr::from_str(s) .map_err(Error::from) - .context(format_err!("Could not parse second: '{}'", s)) + .context(anyhow!("Could not parse second: '{}'", s)) .map_err(Error::from) }) .transpose()? @@ -147,11 +147,11 @@ fn create_id_from_clispec(create: &ArgMatches, timed_type: Timed) -> Result<Naiv ndt.with_minute(min) .ok_or_else(|| { - format_err!("Cannot set {} as minute, would yield invalid time!", min) + anyhow!("Cannot set {} as minute, would yield invalid time!", min) })? .with_second(sec) .ok_or_else(|| { - format_err!("Cannot set {} as second, would yield invalid time!", sec) + anyhow!("Cannot set {} as second, would yield invalid time!", sec) }) }, } diff --git a/bin/domain/imag-diary/src/delete.rs b/bin/domain/imag-diary/src/delete.rs index 0f313989..d80ac6d5 100644 --- a/bin/domain/imag-diary/src/delete.rs +++ b/bin/domain/imag-diary/src/delete.rs @@ -18,8 +18,8 @@ // use chrono::naive::NaiveDateTime as NDT; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Result; + use libimagdiary::diaryid::DiaryId; use libimagrt::runtime::Runtime; @@ -33,7 +33,7 @@ pub fn delete(rt: &Runtime) -> Result<()> { use libimaginteraction::ask::ask_bool; let diaryname = get_diary_name(rt) - .ok_or_else(|| err_msg("No diary selected. Use either the configuration file or the commandline option"))?; + .ok_or_else(|| anyhow!("No diary selected. Use either the configuration file or the commandline option"))?; let to_del_location = rt .cli() @@ -43,13 +43,13 @@ pub fn delete(rt: &Runtime) -> Result<()> { .map(|dt| { debug!("DateTime = {:?}", dt); dt }) .and_then(DateTime::parse) .map(Into::into) - .ok_or_else(|| err_msg("Not deleting entries: missing date/time specification")) + .ok_or_else(|| anyhow!("Not deleting entries: missing date/time specification")) .and_then(|dt: NDT| DiaryId::from_datetime(diaryname.clone(), dt).into_storeid()) .and_then(|id| rt.store().retrieve(id))? .get_location() .clone(); - let mut input = rt.stdin().ok_or_else(|| err_msg("No input stream. Cannot ask for permission"))?; + let mut input = rt.stdin().ok_or_else(|| anyhow!("No input stream. Cannot ask for permission"))?; let mut output = rt.stdout(); if !ask_bool(&format!("Deleting {:?}", to_del_location), Some(true), &mut input, &mut output)? { diff --git a/bin/domain/imag-diary/src/lib.rs b/bin/domain/imag-diary/src/lib.rs index 72984106..b781fdc3 100644 --- a/bin/domain/imag-diary/src/lib.rs +++ b/bin/domain/imag-diary/src/lib.rs @@ -35,7 +35,7 @@ )] #[macro_use] extern crate log; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate resiter; extern crate clap; extern crate chrono; @@ -61,9 +61,9 @@ use libimagrt::application::ImagApplication; use itertools::Itertools; use clap::App; -use failure::Fallible as Result; -use failure::err_msg; -use failure::Error; +use anyhow::Result; + +use anyhow::Error; mod create; mod delete; @@ -84,7 +84,7 @@ use crate::view::view; pub enum ImagDiary {} impl ImagApplication for ImagDiary { 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"))? { "diaries" => diaries(&rt), "create" => create(&rt), "delete" => delete(&rt), @@ -95,7 +95,7 @@ impl ImagApplication for ImagDiary { if rt.handle_unknown_subcommand("imag-diary", other, rt.cli())?.success() { Ok(()) } else { - Err(err_msg("Failed to handle unknown subcommand")) + Err(anyhow!("Failed to handle unknown subcommand")) } }, } diff --git a/bin/domain/imag-diary/src/list.rs b/bin/domain/imag-diary/src/list.rs index 9b4a6b7e..d047d83b 100644 --- a/bin/domain/imag-diary/src/list.rs +++ b/bin/domain/imag-diary/src/list.rs @@ -19,9 +19,9 @@ use std::io::Write; -use failure::Fallible as Result; -use failure::err_msg; -use failure::Error; +use anyhow::Result; + +use anyhow::Error; use resiter::AndThen; use libimagdiary::diary::Diary; @@ -34,7 +34,7 @@ use crate::util::get_diary_name; pub fn list(rt: &Runtime) -> Result<()> { let diaryname = get_diary_name(rt) - .ok_or_else(|| err_msg("No diary selected. Use either the configuration file or the commandline option"))?; + .ok_or_else(|| anyhow!("No diary selected. Use either the configuration file or the commandline option"))?; let mut ids = Diary::entries(rt.store(), &diaryname)? .and_then_ok(|id| DiaryId::from_storeid(&id)) diff --git a/bin/domain/imag-diary/src/util.rs b/bin/domain/imag-diary/src/util.rs index 4a78adec..ce453358 100644 --- a/bin/domain/imag-diary/src/util.rs +++ b/bin/domain/imag-diary/src/util.rs @@ -18,13 +18,11 @@ // use libimagrt::runtime::Runtime; -use libimagerror::errors::ErrorMsg as EM; use toml::Value; use toml_query::read::TomlValueReadExt; -use failure::Error; -use failure::Fallible as Result; -use failure::ResultExt; +use anyhow::Error; +use anyhow::Result; pub fn get_diary_name(rt: &Runtime) -> Option<String> { use libimagdiary::config::get_default_diary_name; @@ -61,7 +59,6 @@ pub fn get_diary_timed_config(rt: &Runtime, diary_name: &str) -> Result<Option<T Some(cfg) => { let v = cfg .read(&format!("diary.diaries.{}.timed", diary_name)) - .context(EM::IO) .map_err(Error::from); match v { @@ -69,7 +66,7 @@ pub fn get_diary_timed_config(rt: &Runtime, diary_name: &str) -> Result<Option<T Ok(Some(_)) => { let s = format!("Type error at 'diary.diaryies.{}.timed': should be either 'd'/'daily', 'h'/'hourly', 'm'/'minutely' or 's'/'secondly'", diary_name); - Err(format_err!("{}", s)) + Err(anyhow!("{}", s)) }, Ok(None) => Ok(None), @@ -89,6 +86,6 @@ pub fn parse_timed_string(s: &str, diary_name: &str) -> Result<Timed> { } else if s == "s" || s == "secondly" { Ok(Timed::Secondly) } else { - Err(format_err!("Cannot parse config: 'diary.diaries.{}.timed = {}'", diary_name, s)) + Err(anyhow!("Cannot parse config: 'diary.diaries.{}.timed = {}'", diary_name, s)) } } diff --git a/bin/domain/imag-diary/src/view.rs b/bin/domain/imag-diary/src/view.rs index 76e10b25..1eb45c50 100644 --- a/bin/domain/imag-diary/src/view.rs +++ b/bin/domain/imag-diary/src/view.rs @@ -17,9 +17,9 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use failure::Fallible as Result; -use failure::err_msg; -use failure::Error; +use anyhow::Result; + +use anyhow::Error; use resiter::AndThen; use resiter::IterInnerOkOrElse; @@ -32,7 +32,7 @@ use libimagentryview::viewer::Viewer; use crate::util::get_diary_name; pub fn view(rt: &Runtime) -> Result<()> { - let diaryname = get_diary_name(rt).ok_or_else(|| err_msg("No diary name"))?; + let diaryname = get_diary_name(rt).ok_or_else(|| anyhow!("No diary name"))?; let hdr = rt.cli().subcommand_matches("view").unwrap().is_present("show-header"); let out = rt.stdout(); let mut outlock = out.lock(); @@ -40,7 +40,7 @@ pub fn view(rt: &Runtime) -> Result<()> { Diary::entries(rt.store(), &diaryname)? .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(|e| viewer.view_entry(&e, &mut outlock).map_err(Error::from).map(|_| e)) .and_then_ok(|e| rt.report_touched(e.get_location()).map_err(Error::from)) .collect() diff --git a/bin/domain/imag-habit/Cargo.toml b/bin/domain/imag-habit/Cargo.toml index e4f96f7b..5e089f5b 100644 --- a/bin/domain/imag-habit/Cargo.toml +++ b/bin/domain/imag-habit/Cargo.toml @@ -23,10 +23,10 @@ maintenance = { status = "actively-developed" } chrono = "0.4.7" log = "0.4.6" toml = "0.5.1" -toml-query = "0.9.2" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } kairos = "0.3.0" prettytable-rs = "0.8.0" -failure = "0.1.5" +anyhow = "1" resiter = "0.4.0" result-inspect = "0.1" diff --git a/bin/domain/imag-habit/src/lib.rs b/bin/domain/imag-habit/src/lib.rs index 9fa666e1..c2c2aa75 100644 --- a/bin/domain/imag-habit/src/lib.rs +++ b/bin/domain/imag-habit/src/lib.rs @@ -42,7 +42,7 @@ extern crate kairos; extern crate resiter; extern crate chrono; extern crate prettytable; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate result_inspect; extern crate libimaghabit; @@ -57,9 +57,9 @@ use std::io::Write; use prettytable::Table; use prettytable::Cell; use prettytable::Row; -use failure::Error; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Error; +use anyhow::Result; + use resiter::AndThen; use resiter::FilterMap; use resiter::Filter; @@ -87,7 +87,7 @@ mod ui; pub enum ImagHabit {} impl ImagApplication for ImagHabit { 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"))? { "create" => create(&rt), "delete" => delete(&rt), "list" => list(&rt), @@ -100,7 +100,7 @@ impl ImagApplication for ImagHabit { if rt.handle_unknown_subcommand("imag-contact", other, rt.cli())?.success() { Ok(()) } else { - Err(err_msg("Failed to handle unknown subcommand")) + Err(anyhow!("Failed to handle unknown subcommand")) } }, } @@ -132,16 +132,17 @@ fn create(rt: &Runtime) -> Result<()> { let comm = scmd.value_of("create-comment").map(String::from).unwrap(); // safe by clap let date = scmd.value_of("create-date").unwrap(); // safe by clap - let parsedate = |d, pname| match kairos_parse(d)? { + let parsedate = |d, pname| match kairos_parse(d).map_err(|e| Error::from(e.compat()))? { Parsed::TimeType(tt) => tt.calculate() + .map_err(|e| Error::from(e.compat())) .inspect(|y| debug!("TimeType yielded: '{:?}'", y))? .get_moment() .ok_or_else(|| { - format_err!("Error: '{}' parameter does not yield a point in time", pname) + anyhow!("Error: '{}' parameter does not yield a point in time", pname) }) .map(|p| p.date()), _ => { - Err(format_err!("Error: '{}' parameter does not yield a point in time", pname)) + Err(anyhow!("Error: '{}' parameter does not yield a point in time", pname)) }, }; @@ -177,13 +178,13 @@ fn delete(rt: &Runtime) -> Result<()> { let yes = scmd.is_present("delete-yes"); let delete_instances = scmd.is_present("delete-instances"); - let mut input = rt.stdin().ok_or_else(|| err_msg("No input stream. Cannot ask for permission"))?; + let mut input = rt.stdin().ok_or_else(|| anyhow!("No input stream. Cannot ask for permission"))?; let mut output = rt.stdout(); rt.store() .all_habit_templates()? .and_then_ok(|sid| rt.store().get(sid.clone()).map(|e| e.map(|e| (sid, e)))) // get the FileLockEntry - .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(|(sid, h)| { let filter_result = h.habit_name()? == name; Ok((filter_result, sid, h)) @@ -201,7 +202,7 @@ fn delete(rt: &Runtime) -> Result<()> { fle.linked_instances()? .and_then_ok(|instance| { let instance = rt.store().get(instance.clone())?.ok_or_else(|| { - format_err!("Failed to find instance: {}", instance) + anyhow!("Failed to find instance: {}", instance) })?; if instance.get_template_name()? == t_name { @@ -248,7 +249,7 @@ fn delete(rt: &Runtime) -> Result<()> { // future flag. If it is true, the check will not be performed and it is assumed that `--future` // was passed. fn today(rt: &Runtime, future: bool) -> Result<()> { - use failure::ResultExt; + use anyhow::Context; let (future, show_done) = { if !future { @@ -269,7 +270,7 @@ fn today(rt: &Runtime, future: bool) -> Result<()> { .store() .all_habit_templates()? .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(|h| { let due = h.next_instance_date()?; // today or in future @@ -307,7 +308,7 @@ fn today(rt: &Runtime, future: bool) -> Result<()> { am.value_of("today-show-next-n") .map(|x| { x.parse::<usize>() - .context(format_err!("Cannot parse String '{}' to integer", x)) + .context(anyhow!("Cannot parse String '{}' to integer", x)) .map_err(Error::from) }) }).unwrap_or(Ok(5))?; @@ -441,7 +442,7 @@ fn list(rt: &Runtime) -> Result<()> { .all_habit_templates()? .filter_map_ok(|id| match rt.store().get(id.clone()) { Ok(Some(h)) => Some(Ok(h)), - Ok(None) => Some(Err(format_err!("No habit found for {:?}", id))), + Ok(None) => Some(Err(anyhow!("No habit found for {:?}", id))), Err(e) => Some(Err(e)), }) .and_then_ok(|r| r) @@ -495,7 +496,7 @@ fn show(rt: &Runtime) -> Result<()> { rt.store() .all_habit_templates()? .into_get_iter(rt.store()) - .map_inner_ok_or_else(|| err_msg("Did not find one habit template")) + .map_inner_ok_or_else(|| anyhow!("Did not find one habit template")) .filter_ok(|h| h.habit_name().map(|n| name == n).unwrap_or(false)) .and_then_ok(|habit| { let name = habit.habit_name()?; @@ -518,7 +519,7 @@ fn show(rt: &Runtime) -> Result<()> { drop(habit); instances .into_get_iter(rt.store()) - .map_inner_ok_or_else(|| err_msg("Did not find one habit template")) + .map_inner_ok_or_else(|| anyhow!("Did not find one habit template")) .and_then_ok(|e| { let mut v = vec![format!("{}", j)]; let mut instances = instance_lister_fn(&rt, &e)?; @@ -554,7 +555,7 @@ fn done(rt: &Runtime) -> Result<()> { .store() .all_habit_templates()? .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(|h| { let due = h.next_instance_date()?; let take = due.map(|d| d <= today || scmd.is_present("allow-future")).unwrap_or(false); diff --git a/bin/domain/imag-log/Cargo.toml b/bin/domain/imag-log/Cargo.toml index 6bb3eeb2..4160304f 100644 --- a/bin/domain/imag-log/Cargo.toml +++ b/bin/domain/imag-log/Cargo.toml @@ -22,10 +22,10 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.6" toml = "0.5.1" -toml-query = "0.9.2" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } is-match = "0.1.0" itertools = "0.8.0" -failure = "0.1.5" +anyhow = "1" textwrap = "0.11.0" resiter = "0.4.0" diff --git a/bin/domain/imag-log/src/lib.rs b/bin/domain/imag-log/src/lib.rs index 28e02bdc..8440fbd8 100644 --- a/bin/domain/imag-log/src/lib.rs +++ b/bin/domain/imag-log/src/lib.rs @@ -40,7 +40,7 @@ extern crate clap; extern crate toml; extern crate toml_query; extern crate itertools; -extern crate failure; +#[macro_use] extern crate anyhow; extern crate textwrap; extern crate resiter; @@ -54,9 +54,9 @@ use std::io::Write; use std::io::Cursor; use std::str::FromStr; -use failure::Error; -use failure::err_msg; -use failure::Fallible as Result; +use anyhow::Error; + +use anyhow::Result; use resiter::Map; use resiter::AndThen; use resiter::IterInnerOkOrElse; @@ -92,7 +92,7 @@ impl ImagApplication for ImagLog { if rt.handle_unknown_subcommand("imag-bookmark", other, rt.cli())?.success() { Ok(()) } else { - Err(err_msg("Failed to handle unknown subcommand")) + Err(anyhow!("Failed to handle unknown subcommand")) } }, } @@ -186,7 +186,7 @@ fn show(rt: &Runtime) -> Result<()> { let v = iters.into_iter() .flatten() .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(|e| e.is_log().map(|b| (b, e))) .filter_ok(|tpl| tpl.0) .map_ok(|tpl| tpl.1) @@ -228,20 +228,20 @@ fn get_diary_name(rt: &Runtime) -> Result<String> { let cfg = rt .config() - .ok_or_else(|| err_msg("Configuration not present, cannot continue"))?; + .ok_or_else(|| anyhow!("Configuration not present, cannot continue"))?; let current_log = cfg .read_string("log.default")? - .ok_or_else(|| err_msg("Configuration missing: 'log.default'"))?; + .ok_or_else(|| anyhow!("Configuration missing: 'log.default'"))?; if cfg .read("log.logs")? - .ok_or_else(|| err_msg("Configuration missing: 'log.logs'"))? + .ok_or_else(|| anyhow!("Configuration missing: 'log.logs'"))? .as_array() - .ok_or_else(|| err_msg("Configuration 'log.logs' is not an Array"))? + .ok_or_else(|| anyhow!("Configuration 'log.logs' is not an Array"))? .iter() .map(|e| if !is_match!(e, &Value::String(_)) { - Err(err_msg("Configuration 'log.logs' is not an Array<String>!")) + Err(anyhow!("Configuration 'log.logs' is not an Array<String>!")) } else { Ok(e) }) @@ -252,7 +252,7 @@ fn get_diary_name(rt: &Runtime) -> Result<String> { .find(|log| *log == ¤t_log) .is_none() { - Err(err_msg("'log.logs' does not contain 'log.default'")) + Err(anyhow!("'log.logs' does not contain 'log.default'")) } else { Ok(current_log) } diff --git a/bin/domain/imag-mail/Cargo.toml b/bin/domain/imag-mail/Cargo.toml index fd871089..0d1fadad 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.6" -failure = "0.1.5" +anyhow = "1" resiter = "0.4" handlebars = "2" walkdir = "2" @@ -41,7 +41,8 @@ default-features = false features = ["color", "suggestions", "wrap_help"] [dependencies.toml-query] -version = "0.9.2" +git = "https://github.com/matthiasbeyer/toml-query" +branch = "master" default-features = false features = ["typed"] diff --git a/bin/domain/imag-mail/src/lib.rs b/bin/domain/imag-mail/src/lib.rs index 10d6b850..ceee854d 100644 --- a/bin/domain/imag-mail/src/lib.rs +++ b/bin/domain/imag-mail/src/lib.rs @@ -36,7 +36,7 @@ extern crate clap; #[macro_use] extern crate log; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate toml_query; extern crate resiter; extern crate handlebars; @@ -53,9 +53,9 @@ extern crate libimaginteraction; use std::path::PathBuf; -use failure::Fallible as Result; -use failure::err_msg; -use failure::Error; +use anyhow::Result; + +use anyhow::Error; use toml_query::read::TomlValueReadTypeExt; use clap::App; use resiter::AndThen; @@ -84,7 +84,7 @@ mod util; 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"))? { "scan" => scan(&rt), "import-mail" => import_mail(&rt), "list" => list(&rt), @@ -95,7 +95,7 @@ impl ImagApplication for ImagMail { if rt.handle_unknown_subcommand("imag-mail", other, rt.cli())?.success() { Ok(()) } else { - Err(err_msg("Failed to handle unknown subcommand")) + Err(anyhow!("Failed to handle unknown subcommand")) } }, } @@ -214,7 +214,7 @@ fn list(rt: &Runtime) -> Result<()> { if rt.ids_from_stdin() { 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); @@ -226,7 +226,7 @@ fn list(rt: &Runtime) -> Result<()> { } .inspect(|id| debug!("Found: {:?}", id)) .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| { crate::util::list_mail(&m, i, &refconfig, &list_format, &mut out)?; rt.report_touched(m.get_location())?; @@ -247,7 +247,7 @@ fn unread(rt: &Runtime) -> Result<()> { if rt.ids_from_stdin() { 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); @@ -257,7 +257,7 @@ fn unread(rt: &Runtime) -> Result<()> { } .inspect(|id| debug!("Found: {:?}", id)) .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| { if !m.is_seen(&refconfig)? { crate::util::list_mail(&m, i, &refconfig, &list_format, &mut out)?; @@ -273,7 +273,7 @@ fn unread(rt: &Runtime) -> Result<()> { fn mail_store(rt: &Runtime) -> Result<()> { let _ = rt.cli().subcommand_matches("mail-store").unwrap(); - Err(format_err!("This feature is currently not implemented.")) + Err(anyhow!("This feature is currently not implemented.")) } fn get_ref_collection_name(rt: &Runtime) -> Result<String> { @@ -282,8 +282,8 @@ fn get_ref_collection_name(rt: &Runtime) -> Result<String> { debug!("Getting configuration: {}", setting_name); rt.config() - .ok_or_else(|| format_err!("No configuration, cannot find collection name for mail collection"))? + .ok_or_else(|| anyhow!("No configuration, cannot find collection name for mail collection"))? .read_string(setting_name)? - .ok_or_else(|| format_err!("Setting missing: {}", setting_name)) + .ok_or_else(|| anyhow!("Setting missing: {}", setting_name)) } diff --git a/bin/domain/imag-mail/src/ui.rs b/bin/domain/imag-mail/src/ui.rs index 324fabb4..319073d5 100644 --- a/bin/domain/imag-mail/src/ui.rs +++ b/bin/domain/imag-mail/src/ui.rs @@ -18,7 +18,7 @@ // use std::path::PathBuf; -use failure::Fallible as Result; +use anyhow::Result; use libimagstore::storeid::StoreId; use libimagrt::runtime::IdPathProvider; diff --git a/bin/domain/imag-mail/src/util.rs b/bin/domain/imag-mail/src/util.rs index 7f116649..bdd27ba2 100644 --- a/bin/domain/imag-mail/src/util.rs +++ b/bin/domain/imag-mail/src/util.rs @@ -21,9 +21,9 @@ use std::collections::BTreeMap; use std::io::Write; use clap::ArgMatches; -use failure::Error; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Error; +use anyhow::Result; + use handlebars::Handlebars; use toml_query::read::TomlValueReadTypeExt; @@ -37,10 +37,10 @@ pub fn get_mail_print_format(config_value_path: &'static str, rt: &Runtime, scmd Some(s) => Ok(s), None => { rt.config() - .ok_or_else(|| err_msg("No configuration file"))? + .ok_or_else(|| anyhow!("No configuration file"))? .read_string(config_value_path) .map_err(Error::from)? - .ok_or_else(|| format_err!("Configuration '{}' does not exist", config_value_path)) + .ok_or_else(|| anyhow!("Configuration '{}' does not exist", config_value_path)) } }?; diff --git a/bin/domain/imag-notes/Cargo.toml b/bin/domain/imag-notes/Cargo.toml index 438bc27a..a653d01d 100644 --- a/bin/domain/imag-notes/Cargo.toml +++ b/bin/domain/imag-notes/Cargo.toml @@ -22,7 +22,7 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.6" itertools = "0.8.0" -failure = "0.1.5" +anyhow = "1" resiter = "0.4.0" libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" } diff --git a/bin/domain/imag-notes/src/lib.rs b/bin/domain/imag-notes/src/lib.rs index 2c71914c..b3148690 100644 --- a/bin/domain/imag-notes/src/lib.rs +++ b/bin/domain/imag-notes/src/lib.rs @@ -37,7 +37,7 @@ extern crate clap; #[macro_use] extern crate log; extern crate itertools; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate resiter; extern crate libimagnotes; @@ -51,9 +51,9 @@ use std::io::Write; use itertools::Itertools; use clap::App; -use failure::Error; -use failure::err_msg; -use failure::Fallible as Result; +use anyhow::Error; + +use anyhow::Result; use resiter::IterInnerOkOrElse; use libimagentryedit::edit::Edit; @@ -74,7 +74,7 @@ mod ui; pub enum ImagNotes {} impl ImagApplication for ImagNotes { 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"))? { "create" => create(&rt), "delete" => delete(&rt), "edit" => edit(&rt), @@ -84,7 +84,7 @@ impl ImagApplication for ImagNotes { if rt.handle_unknown_subcommand("imag-notes", other, rt.cli())?.success() { Ok(()) } else { - Err(err_msg("Failed to handle unknown subcommand")) + Err(anyhow!("Failed to handle unknown subcommand")) } }, } @@ -131,7 +131,7 @@ fn edit(rt: &Runtime) -> Result<()> { rt .store() .get_note(name.clone())? - .ok_or_else(|| format_err!("Name '{}' not found", name)) + .ok_or_else(|| anyhow!("Name '{}' not found", name)) .and_then(|mut note| { note.edit_content(rt).map_warn_err_str("Editing failed")?; rt.report_touched(note.get_location()).map_err(Error::from) @@ -145,7 +145,7 @@ fn list(rt: &Runtime) -> Result<()> { .store() .all_notes()? .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")) .collect::<Result<Vec<_>>>()? .into_iter() .sorted_by(|a, b| match (a.get_name(), b.get_name()) { diff --git a/bin/domain/imag-timetrack/Cargo.toml b/bin/domain/imag-timetrack/Cargo.toml index ee4ae249..bfa66a92 100644 --- a/bin/domain/imag-timetrack/Cargo.toml +++ b/bin/domain/imag-timetrack/Cargo.toml @@ -26,7 +26,8 @@ filters = "0.3.0" itertools = "0.8.0" prettytable-rs = "0.8.0" kairos = "0.3.0" -failure = "0.1.5" +anyhow = "1" +failure = "0.1" resiter = "0.4.0" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } diff --git a/bin/domain/imag-timetrack/src/cont.rs b/bin/domain/imag-timetrack/src/cont.rs index 95a71c1e..cb28d788 100644 --- a/bin/domain/imag-timetrack/src/cont.rs +++ b/bin/domain/imag-timetrack/src/cont.rs @@ -22,8 +22,8 @@ use std::cmp::Ord; use filters::filter::Filter; use itertools::Itertools; use chrono::NaiveDateTime; -use failure::Fallible as Result; -use failure::Error; +use anyhow::Result; +use anyhow::Error; use resiter::Filter as RFilter; use libimagtimetrack::store::TimeTrackStore; diff --git a/bin/domain/imag-timetrack/src/day.rs b/bin/domain/imag-timetrack/src/day.rs index 540aa625..ff5b6574 100644 --- a/bin/domain/imag-timetrack/src/day.rs +++ b/bin/domain/imag-timetrack/src/day.rs @@ -22,8 +22,8 @@ use std::str::FromStr; use filters::filter::Filter; use chrono::NaiveDateTime; -use failure::Fallible as Result; -use failure::Error; +use anyhow::Result; +use anyhow::Error; use resiter::AndThen; use resiter::Filter as RFilter; diff --git a/bin/domain/imag-timetrack/src/lib.rs b/bin/domain/imag-timetrack/src/lib.rs index d03489e8..3f0791d6 100644 --- a/bin/domain/imag-timetrack/src/lib.rs +++ b/bin/domain/imag-timetrack/src/lib.rs @@ -43,7 +43,8 @@ extern crate filters; extern crate itertools; extern crate prettytable; extern crate kairos; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; +extern crate failure; extern crate resiter; extern crate libimagerror; @@ -76,8 +77,8 @@ use crate::week::week; use crate::year::year; use clap::App; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Result; + use libimagrt::runtime::Runtime; use libimagrt::application::ImagApplication; @@ -107,7 +108,7 @@ impl ImagApplication for ImagTimetrack { if rt.handle_unknown_subcommand("imag-bookmark", other, rt.cli())?.success() { Ok(()) } else { - Err(err_msg("Failed to handle unknown subcommand")) + Err(anyhow!("Failed to handle unknown subcommand")) } }, } diff --git a/bin/domain/imag-timetrack/src/list.rs b/bin/domain/imag-timetrack/src/list.rs index d158303b..bf9719be 100644 --- a/bin/domain/imag-timetrack/src/list.rs +++ b/bin/domain/imag-timetrack/src/list.rs @@ -24,9 +24,9 @@ use prettytable::Cell; use kairos::parser::Parsed; use kairos::parser::parse as kairos_parse; use clap::ArgMatches; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; +use anyhow::Result; +use anyhow::Context; +use anyhow::Error; use resiter::Filter; use resiter::AndThen; use resiter::Map; @@ -46,13 +46,14 @@ pub fn list(rt: &Runtime) -> Result<()> { Some(Ok(Parsed::TimeType(tt))) => { let tt = tt .calculate() - .context(format_err!("Failed to calculate date from '{}'", cmd.value_of(name).unwrap()))?; + .map_err(|e| Error::from(e.compat())) + .context(anyhow!("Failed to calculate date from '{}'", cmd.value_of(name).unwrap()))?; Ok(tt.get_moment().cloned()) }, Some(Ok(Parsed::Iterator(_))) => { - Err(format_err!("Expected single point in time, got '{}', which yields a list of dates", cmd.value_of(name).unwrap())) + Err(anyhow!("Expected single point in time, got '{}', which yields a list of dates", cmd.value_of(name).unwrap())) }, - Some(Err(e)) => Err(e), + Some(Err(e)) => Err(Error::from(e.compat())), None => Ok(None), } }; diff --git a/bin/domain/imag-timetrack/src/month.rs b/bin/domain/imag-timetrack/src/month.rs index 941d2ce2..56b3ede2 100644 --- a/bin/domain/imag-timetrack/src/month.rs +++ b/bin/domain/imag-timetrack/src/month.rs @@ -22,8 +22,8 @@ use std::str::FromStr; use filters::filter::Filter; use chrono::NaiveDateTime; -use failure::Error; -use failure::Fallible as Result; +use anyhow::Error; +use anyhow::Result; use resiter::AndThen; use resiter::Filter as RFilter; diff --git a/bin/domain/imag-timetrack/src/shell.rs b/bin/domain/imag-timetrack/src/shell.rs index 5a888d8b..f4dde8d9 100644 --- a/bin/domain/imag-timetrack/src/shell.rs +++ b/bin/domain/imag-timetrack/src/shell.rs @@ -21,9 +21,9 @@ use std::env; use std::process::Command; use filters::filter::Filter; -use failure::Fallible as Result; -use failure::err_msg; -use failure::Error; +use anyhow::Result; + +use anyhow::Error; use resiter::Filter as RFilter; use resiter::AndThen; @@ -60,10 +60,10 @@ pub fn shell(rt: &Runtime) -> Result<()> { .map(mkshell) .map_err(|e| match e { env::VarError::NotPresent => { - err_msg("No $SHELL variable in environment, cannot work!") + anyhow!("No $SHELL variable in environment, cannot work!") }, env::VarError::NotUnicode(_) => { - err_msg("SHELL variable is not unicode, cannot work!") + anyhow!("SHELL variable is not unicode, cannot work!") } }) } @@ -75,7 +75,7 @@ pub fn shell(rt: &Runtime) -> Result<()> { } if !shellcmd.status()?.success() { - return Err(format_err!("Failed to execute {:?}", shellcmd)) + return Err(anyhow!("Failed to execute {:?}", shellcmd)) } let stop = ::chrono::offset::Local::now().naive_local(); let filter = has_one_of_tags(&tags); diff --git a/bin/domain/imag-timetrack/src/start.rs b/bin/domain/imag-timetrack/src/start.rs index abfeb9e6..50ad3c27 100644 --- a/bin/domain/imag-timetrack/src/start.rs +++ b/bin/domain/imag-timetrack/src/start.rs @@ -20,8 +20,8 @@ use std::str::FromStr; use chrono::naive::NaiveDateTime; -use failure::Error; -use failure::Fallible as Result; +use anyhow::Error; +use anyhow::Result; use libimagrt::runtime::Runtime; use libimagtimetrack::tag::TimeTrackingTag; diff --git a/bin/domain/imag-timetrack/src/stop.rs b/bin/domain/imag-timetrack/src/stop.rs index 37b44133..c2662f74 100644 --- a/bin/domain/imag-timetrack/src/stop.rs +++ b/bin/domain/imag-timetrack/src/stop.rs @@ -21,8 +21,8 @@ use std::str::FromStr; use filters::filter::Filter; use chrono::NaiveDateTime; -use failure::Fallible as Result; -use failure::Error; +use anyhow::Result; +use anyhow::Error; use resiter::Filter as RFilter; use resiter::Map; use resiter::AndThen; diff --git a/bin/domain/imag-timetrack/src/track.rs b/bin/domain/imag-timetrack/src/track.rs index d5188bc6..deda6837 100644 --- a/bin/domain/imag-timetrack/src/track.rs +++ b/bin/domain/imag-timetrack/src/track.rs @@ -20,9 +20,9 @@ use clap::ArgMatches; use chrono::naive::NaiveDate; use chrono::naive::NaiveDateTime; -use failure::Error; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Error; +use anyhow::Result; + use libimagrt::runtime::Runtime; use libimagtimetrack::tag::TimeTrackingTag; @@ -48,8 +48,8 @@ pub fn track(rt: &Runtime) -> Result<()> { } } - let start = get_time(&cmd, "start-time")?.ok_or_else(|| err_msg("No start-time"))?; - let stop = get_time(&cmd, "end-time")?.ok_or_else(|| err_msg("No end-time"))?; + let start = get_time(&cmd, "start-time")?.ok_or_else(|| anyhow!("No start-time"))?; + let stop = get_time(&cmd, "end-time")?.ok_or_else(|| anyhow!("No end-time"))?; cmd.values_of("tags") .unwrap() // enforced by clap diff --git a/bin/domain/imag-timetrack/src/week.rs b/bin/domain/imag-timetrack/src/week.rs index 1578f2f8..5a554496 100644 --- a/bin/domain/imag-timetrack/src/week.rs +++ b/bin/domain/imag-timetrack/src/week.rs @@ -22,8 +22,8 @@ use std::str::FromStr; use filters::filter::Filter; use chrono::NaiveDateTime; -use failure::Error; -use failure::Fallible as Result; +use anyhow::Error; +use anyhow::Result; use resiter::AndThen; use resiter::Filter as RFilter; diff --git a/bin/domain/imag-timetrack/src/year.rs b/bin/domain/imag-timetrack/src/year.rs index 70a40a0c..c53a36b0 100644 --- a/bin/domain/imag-timetrack/src/year.rs +++ b/bin/domain/imag-timetrack/src/year.rs @@ -22,8 +22,8 @@ use std::str::FromStr; use filters::filter::Filter; use chrono::NaiveDateTime; -use failure::Error; -use failure::Fallible as Result; +use anyhow::Error; +use anyhow::Result; use resiter::AndThen; use resiter::Filter as RFilter; diff --git a/bin/domain/imag-todo/Cargo.toml b/bin/domain/imag-todo/Cargo.toml index 210f1bce..4e6f0824 100644 --- a/bin/domain/imag-todo/Cargo.toml +++ b/bin/domain/imag-todo/Cargo.toml @@ -22,9 +22,9 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.6" toml = "0.5.1" -toml-query = "0.9.2" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } is-match = "0.1.0" -failure = "0.1.5" +anyhow = "1" chrono = "0.4" filters = "0.3" kairos = "0.3" diff --git a/bin/domain/imag-todo/src/import.rs b/bin/domain/imag-todo/src/import.rs index 8d5b6e81..810faa55 100644 --- a/bin/domain/imag-todo/src/import.rs +++ b/bin/domain/imag-todo/src/import.rs @@ -17,8 +17,8 @@ // 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 anyhow::Error; use libimagrt::runtime::Runtime; @@ -26,14 +26,14 @@ pub fn import(rt: &Runtime) -> Result<()> { let scmd = rt.cli().subcommand().1.unwrap(); match scmd.subcommand_name() { - None => Err(err_msg("No subcommand called")), + None => Err(anyhow!("No subcommand called")), Some("taskwarrior") => import_taskwarrior(rt), Some(other) => { debug!("Unknown command"); if rt.handle_unknown_subcommand("imag-todo-import", other, rt.cli())?.success() { Ok(()) } else { - Err(err_msg("Failed to handle unknown subcommand")) + Err(anyhow!("Failed to handle unknown subcommand")) } }, } @@ -43,7 +43,7 @@ pub fn import(rt: &Runtime) -> Result<()> { fn import_taskwarrior(rt: &Runtime) -> Result<()> { #[cfg(not(feature = "import-taskwarrior"))] { - Err(err_msg("Binary not compiled with taskwarrior import functionality")) + Err(anyhow!("Binary not compiled with taskwarrior import functionality")) } #[cfg(feature = "import-taskwarrior")] @@ -65,7 +65,7 @@ fn import_taskwarrior(rt: &Runtime) -> Result<()> { let store = rt.store(); if !rt.input_is_pipe() { - return Err(err_msg("Cannot get stdin for importing tasks")) + return Err(anyhow!("Cannot get stdin for importing tasks")) } let stdin = ::std::io::stdin(); @@ -86,7 +86,8 @@ fn import_taskwarrior(rt: &Runtime) -> Result<()> { } }; - taskwarrior_import(stdin)? + taskwarrior_import(stdin) + .map_err(|e| Error::from(e.compat()))? .into_iter() .map(|task| { let mut todo = store @@ -103,12 +104,12 @@ fn import_taskwarrior(rt: &Runtime) -> Result<()> { todo.set_content(task.description().clone()); if let Some(tags) = task.tags() { - tags.iter().map(|tag| { + tags.iter().map(String::from).map(|tag| { if libimagentrytag::tag::is_tag_str(&tag).is_err() { warn!("Not a valid tag, ignoring: {}", tag); Ok(()) } else { - todo.add_tag(tag.clone()) + todo.add_tag(tag) } }).collect::<Result<Vec<_>>>()?; } @@ -142,14 +143,14 @@ fn import_taskwarrior(rt: &Runtime) -> Result<()> { .filter(|(_, list)| !list.is_empty()) .map(|(key, list)| { let mut entry = store.get_todo_by_uuid(key)?.ok_or_else(|| { - format_err!("Cannot find todo by UUID: {}", key) + anyhow!("Cannot find todo by UUID: {}", key) })?; list.iter() .map(move |element| { store.get_todo_by_uuid(element)? .ok_or_else(|| { - format_err!("Cannot find todo by UUID: {}", key) + anyhow!("Cannot find todo by UUID: {}", key) }) .and_then(|mut target| entry.add_link(&mut target)) }) diff --git a/bin/domain/imag-todo/src/lib.rs b/bin/domain/imag-todo/src/lib.rs index 42f9baeb..db93004d 100644 --- a/bin/domain/imag-todo/src/lib.rs +++ b/bin/domain/imag-todo/src/lib.rs @@ -41,7 +41,7 @@ extern crate chrono; extern crate filters; extern crate kairos; #[macro_use] extern crate log; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate resiter; extern crate handlebars; extern crate prettytable; @@ -69,14 +69,13 @@ extern crate libimaginteraction; use std::ops::Deref; use std::io::Write; -use std::result::Result as RResult; use std::str::FromStr; use clap::ArgMatches; use chrono::NaiveDateTime; -use failure::Error; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Error; +use anyhow::Result; + use clap::App; use resiter::AndThen; use resiter::IterInnerOkOrElse; @@ -121,7 +120,7 @@ impl ImagApplication for ImagTodo { if rt.handle_unknown_subcommand("imag-todo", other, rt.cli())?.success() { Ok(()) } else { - Err(err_msg("Failed to handle unknown subcommand")) + Err(anyhow!("Failed to handle unknown subcommand")) } } } // end match scmd @@ -219,11 +218,11 @@ fn create(rt: &Runtime) -> Result<()> { fn mark(rt: &Runtime) -> Result<()> { fn mark_todos_as(rt: &Runtime, status: Status) -> 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(|e| rt.report_touched(e.get_location()).map(|_| e)) .and_then_ok(|mut e| e.set_status(status.clone())) .collect() @@ -234,8 +233,8 @@ fn mark(rt: &Runtime) -> Result<()> { Some("done") => mark_todos_as(rt, Status::Done), Some("deleted") => mark_todos_as(rt, Status::Deleted), Some("pending") => mark_todos_as(rt, Status::Pending), - Some(other) => Err(format_err!("Unknown mark type selected: {}", other)), - None => Err(format_err!("No mark type selected, doing nothing!")), + Some(other) => Err(anyhow!("Unknown mark type selected: {}", other)), + None => Err(anyhow!("No mark type selected, doing nothing!")), } } @@ -249,19 +248,17 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul details: bool, } impl Viewer for TodoViewer { - fn view_entry<W>(&self, entry: &Entry, sink: &mut W) -> RResult<(), libimagentryview::error::Error> + fn view_entry<W>(&self, entry: &Entry, sink: &mut W) -> Result<()> where W: Write { - use libimagentryview::error::Error as E; - trace!("Viewing entry: {}", entry.get_location()); - if !entry.is_todo().map_err(E::from)? { - return Err(format_err!("Not a Todo: {}", entry.get_location())).map_err(E::from); + if !entry.is_todo()? { + return Err(anyhow!("Not a Todo: {}", entry.get_location())); } - let uuid = entry.get_uuid().map_err(E::from)?; - let status = entry.get_status().map_err(E::from)?; + let uuid = entry.get_uuid()?; + let status = entry.get_status()?; let status = status.as_str(); let first_line = entry.get_content() .lines() @@ -272,14 +269,14 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul let r = writeln!(sink, "{uuid} - {status} : {first_line}", uuid = uuid, status = status, - first_line = first_line); + first_line = first_line).map_err(Error::from); trace!("Viewing entry result: {:?}", r); r } else { let sched = util::get_dt_str(entry.get_scheduled(), "Not scheduled")?; let hidden = util::get_dt_str(entry.get_hidden(), "Not hidden")?; let due = util::get_dt_str(entry.get_due(), "No due")?; - let priority = entry.get_priority().map_err(E::from)?.map(|p| p.as_str().to_string()) + let priority = entry.get_priority()?.map(|p| p.as_str().to_string()) .unwrap_or_else(|| "No prio".to_string()); let r = writeln!(sink, "{uuid} - {status} - {sched} - {hidden} - {due} - {prio}: {first_line}", @@ -289,12 +286,11 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul hidden = hidden, due = due, prio = priority, - first_line = first_line); + first_line = first_line).map_err(Error::from); trace!("Viewing entry result: {:?}", r); r } - .map_err(libimagentryview::error::Error::from) } } @@ -343,18 +339,18 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul if rt.ids_from_stdin() { trace!("Getting IDs from stdin"); 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")); process(&rt, matcher, show_hidden, iter) } else { trace!("Getting IDs from store"); let iter = rt.store().get_todos()? .into_get_iter() - .map_inner_ok_or_else(|| err_msg("Did not find one entry")); + .map_inner_ok_or_else(|| anyhow!("Did not find one entry")); process(&rt, matcher, show_hidden, iter) } @@ -426,15 +422,13 @@ fn show(rt: &Runtime) -> Result<()> { }; iter.map(|entry| { - use libimagentryview::error::Error as E; - - let uuid = entry.get_uuid().map_err(E::from)?.to_hyphenated().to_string(); - let status = entry.get_status().map_err(E::from)?; + let uuid = entry.get_uuid()?.to_hyphenated().to_string(); + let status = entry.get_status()?; let status = status.as_str().to_string(); let sched = util::get_dt_str(entry.get_scheduled(), "Not scheduled")?; let hidden = util::get_dt_str(entry.get_hidden(), "Not hidden")?; let due = util::get_dt_str(entry.get_due(), "No due")?; - let priority = entry.get_priority().map_err(E::from)?.map(|p| p.as_str().to_string()).unwrap_or_else(|| "No prio".to_string()); + let priority = entry.get_priority()?.map(|p| p.as_str().to_string()).unwrap_or_else(|| "No prio".to_string()); let text = entry.get_content().to_owned(); @@ -461,11 +455,11 @@ fn show(rt: &Runtime) -> Result<()> { 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(|e| rt.report_touched(e.get_location()).map(|_| e)) .collect::<Result<Vec<_>>>()? .into_iter(); @@ -493,13 +487,13 @@ fn get_datetime_arg(scmd: &ArgMatches, argname: &'static str) -> Result<Option<N match scmd.value_of(argname) { None => Ok(None), - Some(v) => match parser::parse(v)? { + Some(v) => match parser::parse(v).map_err(|e| Error::from(e.compat()))? { parser::Parsed::TimeType(TimeType::Moment(moment)) => Ok(Some(moment)), parser::Parsed::TimeType(other) => { - Err(format_err!("You did not pass a date, but a {}", other.name())) + Err(anyhow!("You did not pass a date, but a {}", other.name())) }, parser::Parsed::Iterator(_) => { - Err(format_err!("Argument {} results in a list of dates, but we need a single date.", v)) + Err(anyhow!("Argument {} results in a list of dates, but we need a single date.", v)) } } } @@ -510,7 +504,7 @@ fn prio_from_str<S: AsRef<str>>(s: S) -> Result<Priority> { "h" => Ok(Priority::High), "m" => Ok(Priority::Medium), "l" => Ok(Priority::Low), - other => Err(format_err!("Unsupported Priority: '{}'", other)), + other => Err(anyhow!("Unsupported Priority: '{}'", other)), } } diff --git a/bin/domain/imag-todo/src/ui.rs b/bin/domain/imag-todo/src/ui.rs index 1172bb60..ec64799e 100644 --- a/bin/domain/imag-todo/src/ui.rs +++ b/bin/domain/imag-todo/src/ui.rs @@ -19,7 +19,7 @@ use std::path::PathBuf; use clap::{Arg, ArgMatches, App, SubCommand}; -use failure::Fallible as Result; +use anyhow::Result; use libimagstore::storeid::StoreId; use libimagstore::storeid::IntoStoreId; diff --git a/bin/domain/imag-todo/src/util.rs b/bin/domain/imag-todo/src/util.rs index bafd40a1..9fce60e6 100644 --- a/bin/domain/imag-todo/src/util.rs +++ b/bin/domain/imag-todo/src/util.rs @@ -18,11 +18,10 @@ // use std::collections::BTreeMap; -use std::result::Result as RResult; -use failure::Fallible as Result; -use failure::Error; -use failure::err_msg; +use anyhow::Result; +use anyhow::Error; + use handlebars::Handlebars; use clap::ArgMatches; use chrono::NaiveDateTime; @@ -33,8 +32,8 @@ use libimagstore::store::Entry; use libimagtodo::entry::Todo; use libimagutil::date::datetime_to_string; -pub fn get_dt_str(d: Result<Option<NaiveDateTime>>, s: &str) -> RResult<String, libimagentryview::error::Error> { - Ok(d.map_err(libimagentryview::error::Error::from)? +pub fn get_dt_str(d: Result<Option<NaiveDateTime>>, s: &str) -> Result<String> { + Ok(d? .map(|v| datetime_to_string(&v)) .unwrap_or_else(|| s.to_string())) } @@ -44,10 +43,10 @@ pub fn get_todo_print_format(config_value_path: &'static str, rt: &Runtime, scmd Some(s) => Ok(s), None => { rt.config() - .ok_or_else(|| err_msg("No configuration file"))? + .ok_or_else(|| anyhow!("No configuration file"))? .read_string(config_value_path) .map_err(Error::from)? - .ok_or_else(|| format_err!("Configuration '{}' does not exist", config_value_path)) + .ok_or_else(|| anyhow!("Configuration '{}' does not exist", config_value_path)) } }?; diff --git a/bin/domain/imag-wiki/Cargo.toml b/bin/domain/imag-wiki/Cargo.toml index 820bd90a..b0605867 100644 --- a/bin/domain/imag-wiki/Cargo.toml +++ b/bin/domain/imag-wiki/Cargo.toml @@ -17,11 +17,11 @@ homepage = "http://imag-pim.org" clap = "2.33.0" log = "0.4.6" toml = "0.5.1" -toml-query = "0.9.2" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } is-match = "0.1.0" regex = "1.1.7" filters = "0.3.0" -failure = "0.1.5" +anyhow = "1" resiter = "0.4.0" libimagentryedit = { version = "0.10.0", path = "../../../lib/entry/libimagentryedit" } diff --git a/bin/domain/imag-wiki/src/lib.rs b/bin/domain/imag-wiki/src/lib.rs index cc05194f..331843ec 100644 --- a/bin/domain/imag-wiki/src/lib.rs +++ b/bin/domain/imag-wiki/src/lib.rs @@ -23,7 +23,7 @@ extern crate clap; extern crate regex; extern crate filters; #[macro_use] extern crate log; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate resiter; extern crate libimagrt; @@ -35,10 +35,10 @@ extern crate libimagentrylink; extern crate libimagutil; use std::io::Write; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; -use failure::err_msg; +use anyhow::Result; +use anyhow::Context; +use anyhow::Error; + use clap::App; use resiter::AndThen; @@ -61,7 +61,7 @@ impl ImagApplication for ImagWiki { trace!("wiki_name = {}", wiki_name); trace!("calling = {:?}", rt.cli().subcommand_name()); - 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"))? { "list" => list(&rt, wiki_name), "idof" => idof(&rt, wiki_name), "create" => create(&rt, wiki_name), @@ -73,7 +73,7 @@ impl ImagApplication for ImagWiki { if rt.handle_unknown_subcommand("imag-wiki", other, rt.cli())?.success() { Ok(()) } else { - Err(err_msg("Failed to handle unknown subcommand")) + Err(anyhow!("Failed to handle unknown subcommand")) } } } // end match scmd @@ -110,7 +110,7 @@ fn list(rt: &Runtime, wiki_name: &str) -> Result<()> { rt.store() .get_wiki(wiki_name)? - .ok_or_else(|| format_err!("No wiki '{}' found", wiki_name))? + .ok_or_else(|| anyhow!("No wiki '{}' found", wiki_name))? .all_ids()? .and_then_ok(|id| writeln!(outlock, "{}{}", prefix, id).map_err(Error::from)) .collect::<Result<Vec<_>>>() @@ -130,9 +130,9 @@ fn idof(rt: &Runtime, wiki_name: &str) -> Result<()> { rt.store() .get_wiki(wiki_name)? - .ok_or_else(|| format_err!("No wiki '{}' found", wiki_name))? + .ok_or_else(|| anyhow!("No wiki '{}' found", wiki_name))? .get_entry(&entryname)? - .ok_or_else(|| format_err!("Entry '{}' in wiki '{}' not found!", entryname, wiki_name)) + .ok_or_else(|| anyhow!("Entry '{}' in wiki '{}' not found!", entryname, wiki_name)) .and_then(|entry| { let id = entry.get_location().clone(); let prefix = if scmd.is_present("idof-full") { @@ -152,7 +152,7 @@ fn create(rt: &Runtime, wiki_name: &str) -> Result<()> { let wiki = rt .store() .get_wiki(&wiki_name)? - .ok_or_else(|| format_err!("No wiki '{}' found", wiki_name))?; + .ok_or_else(|| anyhow!("No wiki '{}' found", wiki_name))?; let mut entry = wiki.create_entry(name)?; @@ -214,7 +214,7 @@ fn show(rt: &Runtime, wiki_name: &str) -> Result<()> { let wiki = rt .store() .get_wiki(&wiki_name)? - .ok_or_else(|| format_err!("No wiki '{}' found", wiki_name))?; + .ok_or_else(|| anyhow!("No wiki '{}' found", wiki_name))?; let out = rt.stdout(); let mut outlock = out.lock(); @@ -226,7 +226,7 @@ fn show(rt: &Runtime, wiki_name: &str) -> Result<()> { .map(|name| { let entry = wiki .get_entry(&name)? - .ok_or_else(|| format_err!("No wiki entry '{}' found in wiki '{}'", name, wiki_name))?; + .ok_or_else(|| anyhow!("No wiki entry '{}' found in wiki '{}'", name, wiki_name))?; writeln!(outlock, "{}", entry.get_location())?; writeln!(outlock, "{}", entry.get_content())?; @@ -247,11 +247,11 @@ fn delete(rt: &Runtime, wiki_name: &str) -> Result<()> { let wiki = rt .store() .get_wiki(&wiki_name)? - .ok_or_else(|| format_err!("No wiki '{}' found", wiki_name))?; + .ok_or_else(|| anyhow!("No wiki '{}' found", wiki_name))?; if unlink { wiki.get_entry(&name)? - .ok_or_else(|| format_err!("No wiki entry '{}' in '{}' found", name, wiki_name))? + .ok_or_else(|| anyhow!("No wiki entry '{}' in '{}' found", name, wiki_name))? .unlink(rt.store())?; } diff --git a/lib/core/libimagerror/Cargo.toml b/lib/core/libimagerror/Cargo.toml index 22b6eb8a..2cea7cbd 100644 --- a/lib/core/libimagerror/Cargo.toml +++ b/lib/core/libimagerror/Cargo.toml @@ -20,7 +20,8 @@ is-it-maintained-open-issues = { repository = "matthiasbeyer/imag" } maintenance = { status = "actively-developed" } [dependencies] -log = "0.4.6" -ansi_term = "0.12" -failure = "0.1.5" -failure_derive = "0.1.5" +log = "0.4.6" +toml = "0.5" +ansi_term = "0.12" +thiserror = "1" +anyhow = "1" diff --git a/lib/core/libimagerror/src/errors.rs b/lib/core/libimagerror/src/errors.rs index a1373d91..e74eedaf 100644 --- a/lib/core/libimagerror/src/errors.rs +++ b/lib/core/libimagerror/src/errors.rs @@ -17,88 +17,98 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -#[derive(Debug, Clone, Eq, PartialEq, Fail)] -pub enum ErrorMsg { - #[fail(display = "IO Error")] - IO, +use thiserror::Error; - #[fail(display = "Locking error")] +pub type Result<T> = ::std::result::Result<T, Error>; + +#[derive(Debug, Error)] +pub enum Error { + #[error("IO error")] + IO(#[from] ::std::io::Error), + + #[error("Unknown IO error")] + UnknownIO, + + #[error("Locking error")] LockError, - #[fail(display = "UTF8 error")] - UTF8Error, + #[error("Locking error")] + PoisonError, + + #[error("UTF8 error")] + UTF8Error(#[from] std::str::Utf8Error), - #[fail(display = "Error in external process")] + #[error("Error in external process")] ExternalProcessError, - #[fail(display = "File Error")] + #[error("File Error")] FileError, - #[fail(display = "File not copied")] + #[error("File not copied")] FileNotCopied, - #[fail(display = "File not created")] + #[error("File not created")] FileNotCreated, - #[fail(display = "File not found")] + #[error("File not found")] FileNotFound, - #[fail(display = "Fail not removed")] + #[error("Fail not removed")] FileNotRemoved, - #[fail(display = "Fail not renamed")] + #[error("Fail not renamed")] FileNotRenamed, - #[fail(display = "File not seeked")] + #[error("File not seeked")] FileNotSeeked, - #[fail(display = "File not written")] + #[error("File not written")] FileNotWritten, - #[fail(display = "Directory not created")] + #[error("Directory not created")] DirNotCreated, - #[fail(display = "Formatting error")] - FormatError, + #[error("Formatting error")] + FormatError(#[from] std::fmt::Error), - #[fail(display = "ID is locked")] + #[error("ID is locked")] IdLocked, - #[fail(display = "Error while converting values")] + #[error("Error while converting values")] ConversionError, - #[fail(display = "Entry exists already: {}", _0)] + #[error("Entry exists already: {0}")] EntryAlreadyExists(String), - #[fail(display = "Entry not found: {}", _0)] + #[error("Entry not found: {0}")] EntryNotFound(String), - #[fail(display = "Entry header error")] + #[error("Entry header error")] EntryHeaderError, - #[fail(display = "Entry header type error")] + #[error("Entry header type error")] EntryHeaderTypeError, - #[fail(display = "Entry header type error at '{}', expected '{}'", _0, _1)] + #[error("Entry header type error at '{0}', expected '{1}'")] EntryHeaderTypeError2(&'static str, &'static str), - #[fail(display = "Entry header read error")] + #[error("Entry header read error")] EntryHeaderReadError, - #[fail(display = "Entry header write error")] + #[error("Entry header write error")] EntryHeaderWriteError, - #[fail(display = "Entry header field missing: {}", _0)] + #[error("Entry header field missing: {0}")] EntryHeaderFieldMissing(&'static str), - #[fail(display = "Toml deserialization error")] + #[error("Toml deserialization error")] TomlDeserError, - #[fail(display = "Toml querying error")] + #[error("Toml querying error")] TomlQueryError, } diff --git a/lib/core/libimagerror/src/lib.rs b/lib/core/libimagerror/src/lib.rs index 55d045a6..78d1e2c2 100644 --- a/lib/core/libimagerror/src/lib.rs +++ b/lib/core/libimagerror/src/lib.rs @@ -37,8 +37,9 @@ #[macro_use] extern crate log; extern crate ansi_term; -extern crate failure; -#[macro_use] extern crate failure_derive; +extern crate toml; +extern crate thiserror; +extern crate anyhow; pub mod errors; pub mod exit; diff --git a/lib/core/libimagerror/src/trace.rs b/lib/core/libimagerror/src/trace.rs index 1b192e44..e7bb5a39 100644 --- a/lib/core/libimagerror/src/trace.rs +++ b/lib/core/libimagerror/src/trace.rs @@ -18,48 +18,30 @@ // use std::process::exit; -use std::fmt::Display; -use std::fmt::Formatter; -use std::fmt::Result as FmtResult; -use failure::Error; -use ansi_term::Colour::Red; - -struct ImagTrace<'a, T: 'a + ?Sized>(&'a T); - -impl<'a, T: 'a + ?Sized> ImagTrace<'a, T> { - fn new(d: &'a T) -> ImagTrace<'a, T> { - ImagTrace(d) - } -} - -impl<'a> Display for ImagTrace<'a, Error> -{ - fn fmt(&self, fmt: &mut Formatter) -> FmtResult { - writeln!(fmt, "{}: {}", Red.blink().paint("ERROR[ 0]"), self.0)?; - - { - for (i, cause) in self.0.iter_causes().enumerate() { - writeln!(fmt, - "{prefix}: {error}", - prefix = Red.blink().paint(format!("ERROR[{:>4}]", i + 1)), - error = cause)?; - } - } - - writeln!(fmt, "{}", Red.paint("--- BACKTRACE ---"))?; - writeln!(fmt, "{:?}", self.0.backtrace())?; - - Ok(()) - } -} +use anyhow::Error; +use ansi_term::Colour::Red; pub fn trace_error(e: &Error) { - eprintln!("{}", ImagTrace::new(e)); + eprintln!("{}: {}", Red.blink().paint("ERROR[ 0]"), e); + let mut i = 0; + e.chain().skip(1).for_each(|cause| { + eprintln!("{prefix}: {error}", + prefix = Red.blink().paint(format!("ERROR[{:>4}]", i + 1)), + error = cause); + i += 1; + }); } pub fn trace_error_dbg(e: &Error) { - debug!("{}", ImagTrace::new(e)); + debug!("{}: {}", Red.blink().paint("ERROR[ 0]"), e); + let mut i = 0; + e.chain().skip(1).for_each(|cause| { + debug!("{prefix}: {error}", + prefix = Red.blink().paint(format!("ERROR[{:>4}]", i + 1)), + error = cause); + i += 1; + }); } /// Helper functions for `Result<T, E>` types to reduce overhead in the following situations: diff --git a/lib/core/libimagrt/Cargo.toml b/lib/core/libimagrt/Cargo.toml index 0a5f8841..d6792b51 100644 --- a/lib/core/libimagrt/Cargo.toml +++ b/lib/core/libimagrt/Cargo.toml @@ -26,8 +26,8 @@ xdg-basedir = "1.0.0" itertools = "0.8.0" ansi_term = "0.12" atty = "0.2.11" -failure = "0.1.5" -failure_derive = "0.1.5" +anyhow = "1" + serde_derive = "1.0.94" serde = "1.0.94" @@ -52,7 +52,8 @@ default-features = false features = ["no_logging"] [dependencies.toml-query] -version = "0.9.2" +git = "https://github.com/matthiasbeyer/toml-query" +branch = "master" default-features = false features = [ "typed" ] diff --git a/lib/core/libimagrt/src/application.rs b/lib/core/libimagrt/src/application.rs index 3ff20d1f..cb5b9b26 100644 --- a/lib/core/libimagrt/src/application.rs +++ b/lib/core/libimagrt/src/application.rs @@ -19,7 +19,7 @@ use runtime::Runtime; use clap::App; -use failure::Fallible as Result; +use anyhow::Result; pub trait ImagApplication { fn run(rt: Runtime) -> Result<()>; @@ -34,10 +34,12 @@ pub trait ImagApplication { macro_rules! simple_imag_application_binary { ($application_library:ident, $application_implementor:ident) => { extern crate libimagerror; - extern crate failure; + extern crate anyhow; extern crate $application_library; - use failure::{Error, Fallible as Result, ResultExt}; + use anyhow::Error; + use anyhow::Result; + use anyhow::Context; fn main() { use libimagerror::trace::MapErrTrace; diff --git a/lib/core/libimagrt/src/configuration.rs b/lib/core/libimagrt/src/configuration.rs index 000c20ba..7de02eb3 100644 --- a/lib/core/libimagrt/src/configuration.rs +++ b/lib/core/libimagrt/src/configuration.rs @@ -21,12 +21,12 @@ use std::path::PathBuf; use toml::Value; use clap::App; -use failure::ResultExt; -use failure::Fallible as Result; -use failure::Error; -use failure::err_msg; +use anyhow::Context; +use anyhow::Result; +use anyhow::Error; -use libimagerror::errors::ErrorMsg as EM; + +use libimagerror::errors::Error as EM; /// Get a new configuration object. /// @@ -119,18 +119,17 @@ pub fn override_config(val: &mut Value, v: Vec<String>) -> Result<()> { None })) .map(|(k, v)| { - let value = val.read_mut(&k) - .context(EM::TomlQueryError)? - .ok_or_else(|| err_msg("No config value there, cannot override."))?; + let value = val.read_mut(&k)? + .ok_or_else(|| anyhow!("No config value there, cannot override."))?; let new_value = into_value(value, v) - .ok_or_else(|| err_msg("Config override type not matching"))?; + .ok_or_else(|| anyhow!("Config override type not matching"))?; info!("Successfully overridden: {} = {}", k, new_value); *value = new_value; Ok(()) }) - .map(|elem: Result<()>| elem.context(err_msg("Config override error")).map_err(Error::from)) + .map(|elem: Result<()>| elem.context(anyhow!("Config override error")).map_err(Error::from)) .collect::<Result<()>>() } diff --git a/lib/core/libimagrt/src/iter.rs b/lib/core/libimagrt/src/iter.rs index 519d6c65..153aa794 100644 --- a/lib/core/libimagrt/src/iter.rs +++ b/lib/core/libimagrt/src/iter.rs @@ -23,8 +23,8 @@ mod reporting { use libimagstore::store::Entry; use libimagstore::storeid::StoreId; - use failure::Fallible as Result; - use failure::Error; + use anyhow::Result; + use anyhow::Error; use runtime::Runtime; diff --git a/lib/core/libimagrt/src/lib.rs b/lib/core/libimagrt/src/lib.rs index f7c9f579..c36e2d01 100644 --- a/lib/core/libimagrt/src/lib.rs +++ b/lib/core/libimagrt/src/lib.rs @@ -42,7 +42,7 @@ extern crate itertools; extern crate ansi_term; extern crate handlebars; extern crate serde; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; #[macro_use] extern crate toml_query; extern crate clap; diff --git a/lib/core/libimagrt/src/logger.rs b/lib/core/libimagrt/src/logger.rs index c79f2ec2..73c23351 100644 --- a/lib/core/libimagrt/src/logger.rs +++ b/lib/core/libimagrt/src/logger.rs @@ -24,10 +24,9 @@ use std::sync::Arc; use std::sync::Mutex; use std::ops::Deref; -use failure::ResultExt; -use failure::Fallible as Result; -use failure::Error; -use failure::err_msg; +use anyhow::Result; +use anyhow::Error; + use clap::ArgMatches; use log::{Log, Level, Record, Metadata}; use toml::Value; @@ -35,8 +34,6 @@ use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt; use handlebars::Handlebars; -use libimagerror::errors::ErrorMsg as EM; - #[derive(Debug)] enum LogDestination { Stderr, @@ -152,7 +149,7 @@ fn match_log_level_str(s: &str) -> Result<Level> { "info" => Ok(Level::Info), "warn" => Ok(Level::Warn), "error" => Ok(Level::Error), - lvl => Err(format_err!("Invalid logging level: {}", lvl)), + lvl => Err(anyhow!("Invalid logging level: {}", lvl)), } } @@ -175,10 +172,8 @@ fn aggregate_global_loglevel(matches: &ArgMatches, config: Option<&Value>) -> Re if let Some(cfg) = config { let cfg_loglevel = cfg - .read_string("imag.logging.level") - .map_err(Error::from) - .context(EM::TomlQueryError)? - .ok_or_else(|| err_msg("Global log level config missing")) + .read_string("imag.logging.level")? + .ok_or_else(|| anyhow!("Global log level config missing")) .and_then(|s| match_log_level_str(&s))?; if let Some(cli_loglevel) = get_arg_loglevel(matches)? { @@ -208,8 +203,6 @@ fn translate_destination(raw: &str) -> Result<LogDestination> { .map(Arc::new) .map(LogDestination::File) .map_err(Error::from) - .context(EM::IO) - .map_err(Error::from) } } } @@ -218,21 +211,18 @@ fn aggregate_global_destinations(config: Option<&Value>) -> Result<Vec<LogDestin match config { None => Ok(vec![LogDestination::default()]), Some(cfg) => cfg - .read("imag.logging.destinations") - .map_err(Error::from) - .context(EM::TomlQueryError)? - .ok_or_else(|| err_msg("Global log destination config missing"))? + .read("imag.logging.destinations")? + .ok_or_else(|| anyhow!("Global log destination config missing"))? .as_array() .ok_or_else(|| { let msg = "Type error at 'imag.logging.destinations', expected 'Array'"; - err_msg(msg) + anyhow!(msg) }) .and_then(|raw| { raw.iter() .map(|val| { val.as_str() - .ok_or_else(|| "Type error at 'imag.logging.modules.<mod>.destinations', expected Array<String>") - .map_err(err_msg) + .ok_or_else(|| anyhow!("Type error at 'imag.logging.modules.<mod>.destinations', expected Array<String>")) .map_err(Error::from) .and_then(|s| translate_destination(s)) }) @@ -242,29 +232,24 @@ fn aggregate_global_destinations(config: Option<&Value>) -> Result<Vec<LogDestin } mod log_lvl_aggregate { - use failure::Fallible as Result; - use failure::Error as E; - use failure::ResultExt; - use failure::err_msg; + use anyhow::Result; + use anyhow::Error as E; + use anyhow::Context; use toml::Value; use toml_query::read::TomlValueReadTypeExt; use handlebars::Handlebars; - use libimagerror::errors::ErrorMsg as EM; - macro_rules! aggregate_global_format_with { ($t:ident, $read_str:expr) => { pub struct $t; impl LogLevelAggregator for $t { fn aggregate(config: Option<&Value>) -> Result<String> { config.ok_or_else(|| { - E::from(err_msg(concat!("Config missing: Logging format: ", stringify!($t)))) + E::from(anyhow!(concat!("Config missing: Logging format: ", stringify!($t)))) })? - .read_string($read_str) - .map_err(E::from) - .context(EM::TomlQueryError)? + .read_string($read_str)? .ok_or_else(|| { - E::from(err_msg(concat!("Config missing: Logging format: ", stringify!($t)))) + E::from(anyhow!(concat!("Config missing: Logging format: ", stringify!($t)))) }) } } @@ -280,7 +265,7 @@ mod log_lvl_aggregate { { hb.register_template_string(lvlstr, T::aggregate(config)?) .map_err(E::from) - .context(err_msg("Handlebars template error")) + .context(anyhow!("Handlebars template error")) .map_err(E::from) } diff --git a/lib/core/libimagrt/src/runtime.rs b/lib/core/libimagrt/src/runtime.rs index c29a2846..90ad0920 100644 --- a/lib/core/libimagrt/src/runtime.rs +++ b/lib/core/libimagrt/src/runtime.rs @@ -31,16 +31,15 @@ use toml::Value; use toml_query::read::TomlValueReadExt; use clap::{Arg, ArgMatches}; -use failure::ResultExt; -use failure::Fallible as Result; -use failure::Error; -use failure::err_msg; +use anyhow::Context; +use anyhow::Result; +use anyhow::Error; + use crate::configuration::{fetch_config, override_config, InternalConfiguration}; use crate::logger::ImagLogger; use crate::io::OutputProxy; -use libimagerror::errors::ErrorMsg as EM; use libimagerror::trace::*; use libimagstore::store::Store; use libimagstore::storeid::StoreId; @@ -85,10 +84,10 @@ impl<'a> Runtime<'a> { let config = match fetch_config(&configpath)? { None => { - return Err(err_msg("No configuration file found")) - .context(err_msg("Maybe try to use 'imag-init' to initialize imag?")) - .context(err_msg("Continuing without configuration file")) - .context(err_msg("Cannot instantiate runtime")) + return Err(anyhow!("No configuration file found")) + .context(anyhow!("Maybe try to use 'imag-init' to initialize imag?")) + .context(anyhow!("Continuing without configuration file")) + .context(anyhow!("Cannot instantiate runtime")) .map_err(Error::from); }, Some(mut config) => { @@ -160,7 +159,7 @@ impl<'a> Runtime<'a> { input_data, output_data, }) - .context(err_msg("Cannot instantiate runtime")) + .context(anyhow!("Cannot instantiate runtime")) .map_err(Error::from) } @@ -389,15 +388,15 @@ impl<'a> Runtime<'a> { .map(String::from) .ok_or_else(|| { self.config() - .ok_or_else(|| err_msg("No Configuration!")) + .ok_or_else(|| anyhow!("No Configuration!")) .and_then(|v| match v.read("rt.editor")? { Some(&Value::String(ref s)) => Ok(Some(s.clone())), - Some(_) => Err(err_msg("Type error at 'rt.editor', expected 'String'")), + Some(_) => Err(anyhow!("Type error at 'rt.editor', expected 'String'")), None => Ok(None), }) }) .or_else(|_| env::var("EDITOR")) - .map_err(|_| Error::from(EM::IO)) + .map_err(Error::from) .and_then(|s| { debug!("Editing with '{}'", s); let mut split = s.split_whitespace(); @@ -407,7 +406,7 @@ impl<'a> Runtime<'a> { } let mut c = Command::new(command.unwrap()); // secured above c.args(split); - c.stdin(::std::fs::File::open("/dev/tty").context(EM::IO)?); + c.stdin(::std::fs::File::open("/dev/tty")?); c.stderr(::std::process::Stdio::inherit()); Ok(Some(c)) }) @@ -500,7 +499,7 @@ impl<'a> Runtime<'a> { let rtp_str = self.rtp() .to_str() .map(String::from) - .ok_or_else(|| Error::from(EM::IO))?; + .ok_or_else(|| anyhow!("UTF8 Error: Runtimepath is not valid UTF8"))?; let command = format!("{}-{}", command.as_ref(), subcommand.as_ref()); @@ -531,7 +530,6 @@ impl<'a> Runtime<'a> { }, _ => e, }) - .context(EM::IO) .map_err(Error::from) } @@ -568,7 +566,7 @@ impl<'a> Runtime<'a> { return if e.kind() == std::io::ErrorKind::BrokenPipe { Ok(false) } else { - Err(failure::Error::from(e)) + Err(Error::from(e)) } } } @@ -675,7 +673,7 @@ pub fn get_rtp_match<'a>(matches: &ArgMatches<'a>) -> Result<PathBuf> { match env::var("IMAG_RTP").map(PathBuf::from) { Ok(p) => return Ok(p), Err(env::VarError::NotUnicode(_)) => { - return Err(err_msg("Environment variable 'IMAG_RTP' does not contain valid Unicode")) + return Err(anyhow!("Environment variable 'IMAG_RTP' does not contain valid Unicode")) }, Err(env::VarError::NotPresent) => { /* passthrough */ } } @@ -685,10 +683,10 @@ pub fn get_rtp_match<'a>(matches: &ArgMatches<'a>) -> Result<PathBuf> { .map(|mut p| { p.push(".imag"); p }) .map_err(|e| match e { env::VarError::NotUnicode(_) => { - err_msg("Environment variable 'HOME' does not contain valid Unicode") + anyhow!("Environment variable 'HOME' does not contain valid Unicode") }, env::VarError::NotPresent => { - err_msg("You seem to be $HOME-less. Please get a $HOME before using this \ + anyhow!("You seem to be $HOME-less. Please get a $HOME before using this \ software. We are sorry for you and hope you have some \ accommodation anyways.") } diff --git a/lib/core/libimagstore/Cargo.toml b/lib/core/libimagstore/Cargo.toml index f14f7c1b..6357b183 100644 --- a/lib/core/libimagstore/Cargo.toml +++ b/lib/core/libimagstore/Cargo.toml @@ -29,8 +29,8 @@ walkdir = "2.2.8" is-match = "0.1.0" serde = "1.0.94" serde_json = "1.0.39" -toml-query = "0.9.2" -failure = "0.1.5" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } +anyhow = "1" libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } libimagutil = { version = "0.10.0", path = "../../../lib/etc/libimagutil" } diff --git a/lib/core/libimagstore/src/configuration.rs b/lib/core/libimagstore/src/configuration.rs index 44c21a72..a2b2e1de 100644 --- a/lib/core/libimagstore/src/configuration.rs +++ b/lib/core/libimagstore/src/configuration.rs @@ -19,11 +19,9 @@ use toml::Value; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; - -use libimagerror::errors::ErrorMsg as EM; +use anyhow::Result; +use anyhow::Context; +use anyhow::Error; /// Checks whether the store configuration has a key "implicit-create" which maps to a boolean /// value. If that key is present, the boolean is returned, otherwise false is returned. @@ -34,10 +32,9 @@ pub fn config_implicit_store_create_allowed(config: &Option<Value>) -> Result<bo if let Some(ref t) = *config { t.read_bool(key) - .context(format_err!("Error reading header '{}' in configuration", key)) .map_err(Error::from) - .context(EM::TomlQueryError)? - .ok_or_else(|| format_err!("Config key missing: {}", key)) + .context(anyhow!("Error reading header '{}' in configuration", key))? + .ok_or_else(|| anyhow!("Config key missing: {}", key)) } else { Ok(false) } diff --git a/lib/core/libimagstore/src/file_abstraction/fs.rs b/lib/core/libimagstore/src/file_abstraction/fs.rs index 5388a5c4..58350fca 100644 --- a/lib/core/libimagstore/src/file_abstraction/fs.rs +++ b/lib/core/libimagstore/src/file_abstraction/fs.rs @@ -22,8 +22,6 @@ use std::io::{Seek, SeekFrom, Read}; use std::path::{Path, PathBuf}; use std::sync::Arc; -use libimagerror::errors::ErrorMsg as EM; - use super::FileAbstraction; use super::FileAbstractionInstance; use super::Drain; @@ -33,9 +31,9 @@ use crate::file_abstraction::iter::PathIterator; use crate::file_abstraction::iter::PathIterBuilder; use walkdir::WalkDir; -use failure::ResultExt; -use failure::Fallible as Result; -use failure::Error; +use anyhow::Context; +use anyhow::Result; +use anyhow::Error; #[derive(Debug)] pub struct FSFileAbstractionInstance(PathBuf); @@ -54,12 +52,11 @@ impl FileAbstractionInstance for FSFileAbstractionInstance { Ok(Some(file)) => file, }; - file.seek(SeekFrom::Start(0)).context(EM::FileNotSeeked)?; + file.seek(SeekFrom::Start(0))?; let mut s = String::new(); file.read_to_string(&mut s) - .context(EM::IO) .map_err(Error::from) .map(|_| s) .and_then(|s: String| Entry::from_str(id, &s)) @@ -73,13 +70,12 @@ impl FileAbstractionInstance for FSFileAbstractionInstance { use std::io::Write; let buf = buf.to_str()?.into_bytes(); - let mut file = create_file(&self.0).context(EM::FileNotCreated)?; + let mut file = create_file(&self.0)?; - file.seek(SeekFrom::Start(0)).context(EM::FileNotCreated)?; - file.set_len(buf.len() as u64).context(EM::FileNotWritten)?; - file.write_all(&buf) - .context(EM::FileNotWritten) - .map_err(Error::from) + file.seek(SeekFrom::Start(0))?; + file.set_len(buf.len() as u64)?; + file.write_all(&buf)?; + Ok(()) } } @@ -92,23 +88,18 @@ pub struct FSFileAbstraction {} impl FileAbstraction for FSFileAbstraction { fn remove_file(&self, path: &PathBuf) -> Result<()> { - remove_file(path) - .context(EM::FileNotRemoved) - .map_err(Error::from) + remove_file(path).map_err(Error::from) } fn copy(&self, from: &PathBuf, to: &PathBuf) -> Result<()> { - copy(from, to) - .map(|_| ()) - .context(EM::FileNotCopied) - .map_err(Error::from) + copy(from, to).map(|_| ()).map_err(Error::from) } fn rename(&self, from: &PathBuf, to: &PathBuf) -> Result<()> { if let Some(p) = to.parent() { if !p.exists() { debug!("Creating: {:?}", p); - create_dir_all(&p).context(EM::DirNotCreated)?; + create_dir_all(&p)?; } } else { debug!("Failed to find parent. This looks like it will fail now"); @@ -116,16 +107,12 @@ impl FileAbstraction for FSFileAbstraction { } debug!("Renaming {:?} to {:?}", from, to); - rename(from, to) - .context(EM::FileNotRenamed) - .map_err(Error::from) + rename(from, to).map_err(Error::from) } fn create_dir_all(&self, path: &PathBuf) -> Result<()> { debug!("Creating: {:?}", path); - create_dir_all(path) - .context(EM::DirNotCreated) - .map_err(Error::from) + create_dir_all(path).map_err(Error::from) } fn exists(&self, path: &PathBuf) -> Result<bool> { @@ -183,7 +170,7 @@ impl PathIterBuilder for WalkDirPathIterBuilder { .map(|r| { trace!("Working in PathIterator with {:?}", r); r.map(|e| PathBuf::from(e.path())) - .context(format_err!("Error in Walkdir")) + .context(anyhow!("Error in Walkdir")) .map_err(Error::from) })) } @@ -194,7 +181,7 @@ impl PathIterBuilder for WalkDirPathIterBuilder { debug!(" -> path : {:?}", self.basepath); if !self.basepath.exists() { - Err(format_err!("Does not exist: {}", self.basepath.display())) + Err(anyhow!("Does not exist: {}", self.basepath.display())) } else { Ok(()) } diff --git a/lib/core/libimagstore/src/file_abstraction/inmemory.rs b/lib/core/libimagstore/src/file_abstraction/inmemory.rs index 2deabcae..f6a0e289 100644 --- a/lib/core/libimagstore/src/file_abstraction/inmemory.rs +++ b/lib/core/libimagstore/src/file_abstraction/inmemory.rs @@ -24,11 +24,11 @@ use std::cell::RefCell; use std::sync::Arc; use std::ops::Deref; -use libimagerror::errors::ErrorMsg as EM; +use libimagerror::errors::Error as EM; + +use anyhow::Result; +use anyhow::Error; -use failure::Fallible as Result; -use failure::Error; -use failure::err_msg; use super::FileAbstraction; use super::FileAbstractionInstance; @@ -140,7 +140,7 @@ impl FileAbstraction for InMemoryFileAbstraction { let a = backend.remove(from).ok_or_else(|| EM::FileNotFound)?; let new_entry = { let new_location = if to.starts_with("/") { - let s = to.to_str().map(String::from).ok_or_else(|| err_msg("Failed to convert path to str"))?; + let s = to.to_str().map(String::from).ok_or_else(|| anyhow!("Failed to convert path to str"))?; PathBuf::from(s.replace("/", "")) } else { to.to_path_buf() diff --git a/lib/core/libimagstore/src/file_abstraction/iter.rs b/lib/core/libimagstore/src/file_abstraction/iter.rs index 14649ac9..e24177b1 100644 --- a/lib/core/libimagstore/src/file_abstraction/iter.rs +++ b/lib/core/libimagstore/src/file_abstraction/iter.rs @@ -21,7 +21,7 @@ use std::path::PathBuf; use std::sync::Arc; use std::fmt::Debug; -use failure::Fallible as Result; +use anyhow::Result; use crate::storeid::StoreIdWithBase; use crate::file_abstraction::FileAbstraction; diff --git a/lib/core/libimagstore/src/file_abstraction/mod.rs b/lib/core/libimagstore/src/file_abstraction/mod.rs index f277e0cf..a46151d6 100644 --- a/lib/core/libimagstore/src/file_abstraction/mod.rs +++ b/lib/core/libimagstore/src/file_abstraction/mod.rs @@ -22,7 +22,7 @@ use std::fmt::Debug; use std::collections::HashMap; use std::sync::Arc; -use failure::Fallible as Result; +use anyhow::Result; use crate::store::Entry; use crate::storeid::StoreIdWithBase; diff --git a/lib/core/libimagstore/src/iter.rs b/lib/core/libimagstore/src/iter.rs index 060dc791..cd0b1ad2 100644 --- a/lib/core/libimagstore/src/iter.rs +++ b/lib/core/libimagstore/src/iter.rs @@ -31,7 +31,7 @@ macro_rules! mk_iterator_mod { #[allow(unused_imports)] use crate::store::FileLockEntry; use crate::store::Store; - use failure::Fallible as Result; + use anyhow::Result; pub struct $itername<'a>(Box<dyn Iterator<Item = Result<StoreId>> + 'a>, &'a Store); @@ -144,7 +144,7 @@ use self::get::StoreGetIterator; use self::retrieve::StoreRetrieveIterator; use crate::file_abstraction::iter::PathIterator; use crate::store::Store; -use failure::Fallible as Result; +use anyhow::Result; /// Iterator for iterating over all (or a subset of all) entries /// diff --git a/lib/core/libimagstore/src/lib.rs b/lib/core/libimagstore/src/lib.rs index 754647d0..a7a4be3d 100644 --- a/lib/core/libimagstore/src/lib.rs +++ b/lib/core/libimagstore/src/lib.rs @@ -46,7 +46,7 @@ extern crate semver; extern crate walkdir; #[macro_use] extern crate is_match; extern crate serde_json; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate toml_query; extern crate libimagerror; diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index e5748121..79eb5b3e 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -30,15 +30,15 @@ use std::fmt::Formatter; use std::fmt::Debug; use std::fmt::Error as FMTError; -use libimagerror::errors::ErrorMsg as EM; +use libimagerror::errors::Error as EM; use toml::Value; use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::err_msg; -use failure::Error; +use anyhow::Result; +use anyhow::Context; + +use anyhow::Error; use crate::storeid::{IntoStoreId, StoreId}; use crate::iter::Entries; @@ -70,9 +70,7 @@ impl StoreEntry { #[cfg(feature = "fs-lock")] { - open_file(pb.clone()) - .and_then(|f| f.lock_exclusive()) - .with_context(|| EM::IO)?; + open_file(pb.clone()).and_then(|f| f.lock_exclusive())?; } Ok(StoreEntry { @@ -96,7 +94,7 @@ impl StoreEntry { None => Ok(Entry::new(self.id.clone())) } } else { - Err(format_err!("EntryAlreadyBorrowed: {}", self.id)) + Err(anyhow!("EntryAlreadyBorrowed: {}", self.id)) } } @@ -188,18 +186,15 @@ impl Store { debug!("Building new Store object"); if !location.exists() { if !config_implicit_store_create_allowed(store_config)? { - return Err(format_err!("CreateStoreDirDenied")) - .context(EM::FileError) - .context(EM::IO) - .map_err(Error::from) + return Err(anyhow!("CreateStoreDirDenied")); } backend .create_dir_all(&location) - .context(format_err!("StorePathCreate: {}", location.display()))?; + .context(anyhow!("StorePathCreate: {}", location.display()))?; } else if location.is_file() { debug!("Store path exists as file"); - return Err(format_err!("StorePathExists: {}", location.display())); + return Err(anyhow!("StorePathExists: {}", location.display())); } let store = Store { @@ -222,8 +217,8 @@ impl Store { self.entries .read() - .map_err(|_| Error::from(EM::LockError)) - .context(format_err!("Error while checking whether {} is borrowed", id)) + .map_err(|_| EM::LockError) + .context(anyhow!("Error while checking whether {} is borrowed", id)) .map(|cache| cache.get(&id).map(|e| e.is_borrowed()).unwrap_or(false)) .map_err(Error::from) } @@ -243,20 +238,20 @@ impl Store { if exists { debug!("Entry exists: {:?}", id); - return Err(format_err!("EntryAlreadyExists: {}", id)); + return Err(anyhow!("EntryAlreadyExists: {}", id)); } { let mut hsmap = self .entries .write() - .map_err(|_| Error::from(EM::LockError)) - .context(format_err!("CreateCallError: {}", id))?; + .map_err(|_| EM::LockError) + .context(anyhow!("CreateCallError: {}", id))?; if hsmap.contains_key(&id) { debug!("Cannot create, internal cache already contains: '{}'", id); - return Err(format_err!("EntryAlreadyExists: {}", id)) - .context(format_err!("CreateCallError: {}", id)) + return Err(anyhow!("EntryAlreadyExists: {}", id)) + .context(anyhow!("CreateCallError: {}", id)) .map_err(Error::from) } hsmap.insert(id.clone(), { @@ -288,7 +283,8 @@ impl Store { let entry = self .entries .write() - .map_err(|_| Error::from(EM::LockError)) + .map_err(|_| EM::LockError) + .map_err(Error::from) .and_then(|mut es| { let new_se = StoreEntry::new(self.path().clone(), id.clone(), &self.backend)?; let se = es.entry(id.clone()).or_insert(new_se); @@ -296,7 +292,7 @@ impl Store { se.status = StoreEntryStatus::Borrowed; entry }) - .context(format_err!("RetrieveCallError: {}", id))?; + .context(anyhow!("RetrieveCallError: {}", id))?; debug!("Constructing FileLockEntry: '{}'", id); Ok(FileLockEntry::new(self, entry)) @@ -326,7 +322,7 @@ impl Store { self.retrieve(id.clone()) .map(Some) - .context(format_err!("GetCallError: {}", id)) + .context(anyhow!("GetCallError: {}", id)) .map_err(Error::from) } @@ -339,7 +335,7 @@ impl Store { pub fn update<'a>(&'a self, entry: &mut FileLockEntry<'a>) -> Result<()> { debug!("Updating FileLockEntry at '{}'", entry.get_location()); self._update(entry, false) - .context(format_err!("UpdateCallError: {}", entry.get_location())) + .context(anyhow!("UpdateCallError: {}", entry.get_location())) .map_err(Error::from) } @@ -351,8 +347,7 @@ impl Store { /// it is not public. /// fn _update<'a>(&'a self, entry: &mut FileLockEntry<'a>, modify_presence: bool) -> Result<()> { - let mut hsmap = self.entries.write() - .map_err(|_| Error::from(EM::LockError))?; + let mut hsmap = self.entries.write().map_err(|_| EM::LockError)?; let se = hsmap.get_mut(&entry.location).ok_or_else(|| { EM::EntryNotFound(entry.location.local_display_string()) @@ -388,8 +383,7 @@ impl Store { pub fn flush_cache(&self) -> Result<()> { // We borrow this early so that between the aggregation of the flushables and the actual // flush, there is no borrowing from the store. - let mut hsmap = self.entries.write() - .map_err(|_| Error::from(EM::LockError))?; + let mut hsmap = self.entries.write().map_err(|_| EM::LockError)?; let mut to_flush = vec![]; for (storeid, se) in hsmap.deref() { @@ -409,13 +403,17 @@ impl Store { /// The number of elements in the internal cache pub fn cache_size(&self) -> Result<usize> { - let hsmap = self.entries.read().map_err(|_| Error::from(EM::LockError))?; + let hsmap = self.entries + .read() + .map_err(|_| EM::LockError)?; Ok(hsmap.iter().count()) } /// The size of the internal cache pub fn cache_capacity(&self) -> Result<usize> { - let hsmap = self.entries.read().map_err(|_| Error::from(EM::LockError))?; + let hsmap = self.entries + .read() + .map_err(|_| EM::LockError)?; Ok(hsmap.capacity()) } @@ -428,14 +426,15 @@ impl Store { pub fn get_copy<S: IntoStoreId>(&self, id: S) -> Result<Entry> { let id = id.into_storeid()?; debug!("Retrieving copy of '{}'", id); - let entries = self.entries.write() - .map_err(|_| Error::from(EM::LockError)) - .context(format_err!("RetrieveCopyCallError: {}", id))?; + let entries = self.entries + .write() + .map_err(|_| EM::LockError) + .context(anyhow!("RetrieveCopyCallError: {}", id))?; // if the entry is currently modified by the user, we cannot drop it if entries.get(&id).map(|e| e.is_borrowed()).unwrap_or(false) { return Err(EM::IdLocked) - .context(format_err!("RetrieveCopyCallError: {}", id)) + .context(anyhow!("RetrieveCopyCallError: {}", id)) .map_err(Error::from) } @@ -463,13 +462,13 @@ impl Store { let mut entries = self .entries .write() - .map_err(|_| Error::from(EM::LockError)) - .context(format_err!("DeleteCallError: {}", id))?; + .map_err(|_| EM::LockError) + .context(anyhow!("DeleteCallError: {}", id))?; let do_remove = match entries.get(&id) { Some(e) => if e.is_borrowed() { // entry is currently borrowed, we cannot delete it return Err(Error::from(EM::LockError)) - .context(format_err!("DeleteCallError: {}", id)) + .context(anyhow!("DeleteCallError: {}", id)) .map_err(Error::from) // false } else { // Entry is in the cache @@ -484,7 +483,7 @@ impl Store { if !self.backend.exists(&pb)? { debug!("Seems like {:?} is not even on the FS", pb); return Err(EM::FileNotFound) - .context(format_err!("DeleteCallError: {}", id)) + .context(anyhow!("DeleteCallError: {}", id)) .map_err(Error::from) } // else { continue } @@ -501,8 +500,8 @@ impl Store { self .backend .remove_file(&pb) - .context(EM::FileError) - .context(format_err!("DeleteCallError: {}", id))?; + .map_err(Error::from) + .context(anyhow!("DeleteCallError: {}", id))?; debug!("Deleted"); Ok(()) @@ -527,12 +526,12 @@ impl Store { let hsmap = self .entries .write() - .map_err(|_| Error::from(EM::LockError)) - .context(format_err!("MoveCallError: {} -> {}", entry.get_location(), new_id))?; + .map_err(|_| EM::LockError) + .context(anyhow!("MoveCallError: {} -> {}", entry.get_location(), new_id))?; if hsmap.contains_key(&new_id) { - return Err(format_err!("Entry exists already: {}", new_id.clone())) - .context(format_err!("MoveCallError: {} -> {}", entry.get_location(), new_id)) + return Err(anyhow!("Entry exists already: {}", new_id.clone())) + .context(anyhow!("MoveCallError: {} -> {}", entry.get_location(), new_id)) .map_err(Error::from) } @@ -548,8 +547,7 @@ impl Store { } else { Ok(()) }) - .context(EM::FileError) - .context(format_err!("MoveCallError: {} -> {}", old_id, new_id)) + .context(anyhow!("MoveCallError: {} -> {}", old_id, new_id)) .map_err(Error::from) } @@ -591,10 +589,10 @@ impl Store { { let mut hsmap = self.entries.write() - .map_err(|_| Error::from(EM::LockError))?; + .map_err(|_| EM::LockError)?; if hsmap.contains_key(&new_id) { - return Err(format_err!("Entry already exists: {}", new_id)); + return Err(anyhow!("Entry already exists: {}", new_id)); } debug!("New id does not exist in cache"); @@ -602,7 +600,7 @@ impl Store { let new_id_pb = new_id.clone().with_base(self.path()).into_pathbuf()?; if !self.backend.exists(&old_id_pb)? { - return Err(format_err!("Entry does not exist: {}", old_id)); + return Err(anyhow!("Entry does not exist: {}", old_id)); } // if it is borrowed, we really should not rename it, as this might @@ -610,11 +608,11 @@ impl Store { // // Also, remove this object from the cache if hsmap.remove(&old_id).map(|e| e.is_borrowed()).unwrap_or(false) { - return Err(format_err!("Entry already borrowed: {}", old_id)); + return Err(anyhow!("Entry already borrowed: {}", old_id)); } if self.backend.exists(&new_id_pb)? { - return Err(format_err!("Entry already exists: {}", new_id)); + return Err(anyhow!("Entry already exists: {}", new_id)); } debug!("New entry does not yet exist on filesystem. Good."); @@ -624,7 +622,7 @@ impl Store { .context({ let old = old_id_pb.display().to_string(); let new = new_id_pb.display().to_string(); - format_err!("Rename error: {} -> {}", old, new) + anyhow!("Rename error: {} -> {}", old, new) })?; debug!("Rename worked on filesystem"); @@ -647,9 +645,9 @@ impl Store { let cache_has_entry = |id: &StoreId| self.entries .read() + .map_err(|_| EM::LockError) .map(|map| map.contains_key(id)) - .map_err(|_| Error::from(EM::LockError)) - .context(format_err!("CreateCallError: {}", id)); + .context(anyhow!("CreateCallError: {}", id)); let backend_has_entry = |id: StoreId| self.backend.exists(&id.with_base(self.path()).into_pathbuf()?); @@ -795,7 +793,7 @@ impl Entry { pub fn from_reader<S: IntoStoreId>(loc: S, file: &mut dyn Read) -> Result<Entry> { let text = { let mut s = String::new(); - file.read_to_string(&mut s).context(EM::IO)?; + file.read_to_string(&mut s)?; s }; Self::from_str(loc, &text[..]) @@ -833,7 +831,7 @@ impl Entry { Ok(format!("---\n{header}---\n{content}", header = ::toml::ser::to_string_pretty(&self.header) .map_err(Error::from) - .context(err_msg("TOML Error"))?, + .context(anyhow!("TOML Error"))?, content = self.content)) } @@ -882,12 +880,12 @@ impl Entry { /// Currently, this only verifies the header. This might change in the future. pub fn verify(&self) -> Result<()> { if !has_main_section(&self.header)? { - Err(format_err!("MissingMainSection")) + Err(anyhow!("MissingMainSection")) } else if !has_imag_version_in_main_section(&self.header)? { - Err(format_err!("MissingVersionInfo")) + Err(anyhow!("MissingVersionInfo")) } else if !has_only_tables(&self.header)? { debug!("Could not verify that it only has tables in its base table"); - Err(format_err!("NonTableInBaseTable")) + Err(anyhow!("NonTableInBaseTable")) } else { Ok(()) } @@ -909,23 +907,19 @@ fn has_only_tables(t: &Value) -> Result<bool> { debug!("Verifying that table has only tables"); match *t { Value::Table(ref tab) => Ok(tab.iter().all(|(_, x)| is_match!(*x, Value::Table(_)))), - _ => Err(format_err!("HeaderTypeFailure")), + _ => Err(anyhow!("HeaderTypeFailure")), } } fn has_main_section(t: &Value) -> Result<bool> { - t.read("imag") - .map_err(Error::from) - .context(EM::TomlQueryError)? - .ok_or_else(|| format_err!("ConfigKeyMissingError('imag')")) + t.read("imag")? + .ok_or_else(|| anyhow!("ConfigKeyMissingError('imag')")) .map(Value::is_table) } fn has_imag_version_in_main_section(t: &Value) -> Result<bool> { - t.read_string("imag.version") - .map_err(Error::from) - .context(EM::TomlQueryError)? - .ok_or_else(|| format_err!("ConfigKeyMissingError('imag.version')")) + t.read_string("imag.version")? + .ok_or_else(|| anyhow!("ConfigKeyMissingError('imag.version')")) .map_err(Error::from) .map(String::from) .map(|s: String| ::semver::Version::parse(&s).is_ok()) diff --git a/lib/core/libimagstore/src/storeid.rs b/lib/core/libimagstore/src/storeid.rs index 3972f376..22f15734 100644 --- a/lib/core/libimagstore/src/storeid.rs +++ b/lib/core/libimagstore/src/storeid.rs @@ -26,10 +26,10 @@ use std::fmt::Error as FmtError; use std::result::Result as RResult; use std::path::Components; -use failure::ResultExt; -use failure::Fallible as Result; -use failure::err_msg; -use failure::Error; +use anyhow::Context; +use anyhow::Result; + +use anyhow::Error; use crate::store::Store; @@ -52,7 +52,7 @@ impl StoreId { debug!("Trying to get a new baseless id from: {:?}", id); if id.is_absolute() { debug!("Error: Id is absolute!"); - Err(format_err!("Store Id local part is absolute: {}", id.display())) + Err(anyhow!("Store Id local part is absolute: {}", id.display())) } else { debug!("Building Storeid object baseless"); Ok(StoreId(id)) @@ -184,11 +184,11 @@ impl<'a> StoreIdWithBase<'a> { store_part.display()); let p = full_path .strip_prefix(store_part) - .context(format_err!("Cannot strip prefix '{}' from path: '{}'", + .context(anyhow!("Cannot strip prefix '{}' from path: '{}'", store_part.display(), full_path.display())) .map_err(Error::from) - .context(err_msg("Error building Store Id from full path"))?; + .context(anyhow!("Error building Store Id from full path"))?; Ok(StoreIdWithBase(store_part, PathBuf::from(p))) } } @@ -227,7 +227,7 @@ macro_rules! module_entry_path_mod { use std::path::Path; use std::path::PathBuf; use $crate::storeid::StoreId; - use failure::Fallible as Result; + use anyhow::Result; pub fn new_id<P: AsRef<Path>>(p: P) -> Result<StoreId> { @@ -235,7 +235,7 @@ macro_rules! module_entry_path_mod { .as_ref() .to_str() .ok_or_else(|| { - format_err!("File path is not valid UTF-8: {}", p.as_ref().display()) + anyhow!("File path is not valid UTF-8: {}", p.as_ref().display()) })?; let id = format!("{}/{}", $name, path_str); diff --git a/lib/core/libimagstore/src/util.rs b/lib/core/libimagstore/src/util.rs index 946cfd94..e113b14c 100644 --- a/lib/core/libimagstore/src/util.rs +++ b/lib/core/libimagstore/src/util.rs @@ -20,10 +20,7 @@ use std::fmt::Write; use toml::Value; -use failure::Fallible as Result; -use failure::ResultExt; - -use libimagerror::errors::ErrorMsg as EM; +use anyhow::Result; #[cfg(feature = "early-panic")] #[macro_export] @@ -55,15 +52,15 @@ pub fn entry_buffer_to_header_content(buf: &str) -> Result<(Value, String)> { header_consumed = true; // do not further process the line } else if !header_consumed { - writeln!(header, "{}", line).context(EM::FormatError)?; + writeln!(header, "{}", line)?; } else if iter.peek().is_some() { - writeln!(content, "{}", line).context(EM::FormatError)?; + writeln!(content, "{}", line)?; } else { - write!(content, "{}", line).context(EM::FormatError)?; + write!(content, "{}", line)?; } } - let h = ::toml::de::from_str(&header).context(EM::TomlDeserError)?; + let h = ::toml::de::from_str(&header)?; Ok((h, content)) } diff --git a/lib/domain/libimagbookmark/Cargo.toml b/lib/domain/libimagbookmark/Cargo.toml index eb441965..fbabc17c 100644 --- a/lib/domain/libimagbookmark/Cargo.toml +++ b/lib/domain/libimagbookmark/Cargo.toml @@ -22,7 +22,7 @@ maintenance = { status = "actively-developed" } [dependencies] url = "2" regex = "1.1.7" -failure = "0.1.5" +anyhow = "1" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } diff --git a/lib/domain/libimagbookmark/src/bookmark.rs b/lib/domain/libimagbookmark/src/bookmark.rs index 0e2d7695..a7f8438c 100644 --- a/lib/domain/libimagbookmark/src/bookmark.rs +++ b/lib/domain/libimagbookmark/src/bookmark.rs @@ -17,7 +17,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use failure::Fallible as Result; +use anyhow::Result; use libimagentryutil::isa::Is; use libimagentryutil::isa::IsKindHeaderPathProvider; diff --git a/lib/domain/libimagbookmark/src/lib.rs b/lib/domain/libimagbookmark/src/lib.rs index bef622cf..c46486e4 100644 --- a/lib/domain/libimagbookmark/src/lib.rs +++ b/lib/domain/libimagbookmark/src/lib.rs @@ -40,7 +40,7 @@ extern crate url; extern crate uuid; extern crate regex; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; #[macro_use] extern crate libimagstore; #[macro_use] extern crate libimagentryutil; diff --git a/lib/domain/libimagbookmark/src/store.rs b/lib/domain/libimagbookmark/src/store.rs index 536e8900..a9519302 100644 --- a/lib/domain/libimagbookmark/src/store.rs +++ b/lib/domain/libimagbookmark/src/store.rs @@ -17,7 +17,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use failure::Fallible as Result; +use anyhow::Result; use uuid::Uuid; use url::Url; @@ -73,7 +73,7 @@ impl BookmarkStore for Store { fn get_bookmark_by_id<'a>(&'a self, sid: StoreId) -> Result<Option<FileLockEntry<'a>>> { if let Some(entry) = self.get(sid)? { if !entry.is_bookmark()? { - Err(format_err!("Not a bookmark: {}", entry.get_location())) + Err(anyhow!("Not a bookmark: {}", entry.get_location())) } else { Ok(Some(entry)) } @@ -92,7 +92,7 @@ impl BookmarkStore for Store { drop(fle); self.delete(id) } else { - Err(format_err!("Not a bookmark: {}", fle.get_location())) + Err(anyhow!("Not a bookmark: {}", fle.get_location())) } } diff --git a/lib/domain/libimagcalendar/Cargo.toml b/lib/domain/libimagcalendar/Cargo.toml index b63ad0c3..809825f9 100644 --- a/lib/domain/libimagcalendar/Cargo.toml +++ b/lib/domain/libimagcalendar/Cargo.toml @@ -20,12 +20,13 @@ is-it-maintained-open-issues = { repository = "matthiasbeyer/imag" } maintenance = { status = "actively-developed" } [dependencies] -failure = "0.1" +anyhow = "1" log = "0.4" toml = "0.5" -toml-query = "0.9" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } vobject = "0.7" chrono = "0.4" +failure = "0.1" libimagentrylink = { version = "0.10.0", path = "../../../lib/entry/libimagentrylink" } libimagentryref = { version = "0.10.0", path = "../../../lib/entry/libimagentryref" } diff --git a/lib/domain/libimagcalendar/src/event.rs b/lib/domain/libimagcalendar/src/event.rs index e2aaaccb..550d2c1a 100644 --- a/lib/domain/libimagcalendar/src/event.rs +++ b/lib/domain/libimagcalendar/src/event.rs @@ -17,7 +17,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use failure::Fallible as Result; +use anyhow::Result; use libimagentryutil::isa::Is; use libimagentryutil::isa::IsKindHeaderPathProvider; diff --git a/lib/domain/libimagcalendar/src/lib.rs b/lib/domain/libimagcalendar/src/lib.rs index fd3b8721..360ecc64 100644 --- a/lib/domain/libimagcalendar/src/lib.rs +++ b/lib/domain/libimagcalendar/src/lib.rs @@ -38,10 +38,11 @@ #![recursion_limit="128"] #[macro_use] extern crate log; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate vobject; extern crate toml; extern crate toml_query; +extern crate failure; #[macro_use] extern crate libimagstore; extern crate libimagerror; diff --git a/lib/domain/libimagcalendar/src/store.rs b/lib/domain/libimagcalendar/src/store.rs index e18b8fe1..14d27921 100644 --- a/lib/domain/libimagcalendar/src/store.rs +++ b/lib/domain/libimagcalendar/src/store.rs @@ -19,10 +19,11 @@ use std::path::Path; -use failure::Fallible as Result; +use anyhow::Result; use toml::Value; use toml_query::insert::TomlValueInsertExt; use vobject::ICalendar; +use failure::Fail; use libimagentryutil::isa::Is; use libimagentryref::reference::Config; @@ -75,7 +76,8 @@ impl<'a> EventStore<'a> for Store { Coll: AsRef<str> { let text = std::fs::read_to_string(p.as_ref())?; - Ok(ICalendar::build(&text)? + Ok(ICalendar::build(&text) + .map_err(|e| e.compat())? .events() .filter_map(|rresult| match rresult { Ok(event) => Some(event), @@ -86,7 +88,7 @@ impl<'a> EventStore<'a> for Store { }) .map(|event| { let uid = event.uid().ok_or_else(|| { - format_err!("Event in {} has no UID, but icalendar events must have one.", p.as_ref().display()) + anyhow!("Event in {} has no UID, but icalendar events must have one.", p.as_ref().display()) })?; let sid = crate::module_path::new_id(uid.raw())?; diff --git a/lib/domain/libimagcontact/Cargo.toml b/lib/domain/libimagcontact/Cargo.toml index 0e13a0e0..d2f740ad 100644 --- a/lib/domain/libimagcontact/Cargo.toml +++ b/lib/domain/libimagcontact/Cargo.toml @@ -20,10 +20,11 @@ is-it-maintained-open-issues = { repository = "matthiasbeyer/imag" } maintenance = { status = "actively-developed" } [dependencies] -failure = "0.1.5" +anyhow = "1" +failure = "0.1" log = "0.4.6" toml = "0.5.1" -toml-query = "0.9.2" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } vobject = "0.7.0" uuid = "0.7.4" serde = "1.0.94" diff --git a/lib/domain/libimagcontact/src/contact.rs b/lib/domain/libimagcontact/src/contact.rs index 50f7a58d..b32edaa6 100644 --- a/lib/domain/libimagcontact/src/contact.rs +++ b/lib/domain/libimagcontact/src/contact.rs @@ -20,13 +20,13 @@ use toml::to_string as toml_to_string; use toml::from_str as toml_from_str; use toml_query::read::TomlValueReadExt; -use failure::Fallible as Result; -use failure::Error; +use anyhow::Result; +use anyhow::Error; use libimagstore::store::Entry; use libimagentryutil::isa::Is; use libimagentryutil::isa::IsKindHeaderPathProvider; -use libimagerror::errors::ErrorMsg as EM; +use libimagerror::errors::Error as EM; use crate::deser::DeserVcard; diff --git a/lib/domain/libimagcontact/src/iter.rs b/lib/domain/libimagcontact/src/iter.rs index 148ff594..c69f2f75 100644 --- a/lib/domain/libimagcontact/src/iter.rs +++ b/lib/domain/libimagcontact/src/iter.rs @@ -20,12 +20,12 @@ use libimagstore::storeid::StoreIdIterator; use libimagstore::store::Store; use libimagstore::store::FileLockEntry; -use libimagerror::errors::ErrorMsg as EM; +use libimagerror::errors::Error as EM; use crate::contact::Contact; -use failure::Fallible as Result; -use failure::Error; -use failure::ResultExt; +use anyhow::Result; +use anyhow::Error; +use anyhow::Context; pub struct ContactIter<'a>(StoreIdIterator, &'a Store); diff --git a/lib/domain/libimagcontact/src/lib.rs b/lib/domain/libimagcontact/src/lib.rs index 7e0d05ac..24692465 100644 --- a/lib/domain/libimagcontact/src/lib.rs +++ b/lib/domain/libimagcontact/src/lib.rs @@ -38,12 +38,13 @@ #![recursion_limit="128"] #[macro_use] extern crate log; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate vobject; extern crate toml; extern crate toml_query; extern crate uuid; extern crate serde; +extern crate failure; #[macro_use] extern crate serde_derive; #[macro_use] extern crate libimagstore; diff --git a/lib/domain/libimagcontact/src/store.rs b/lib/domain/libimagcontact/src/store.rs index 1b679044..527a8fe8 100644 --- a/lib/domain/libimagcontact/src/store.rs +++ b/lib/domain/libimagcontact/src/store.rs @@ -25,9 +25,10 @@ use toml::to_string as toml_to_string; use toml::from_str as toml_from_str; use toml_query::insert::TomlValueInsertExt; use vobject::vcard::Vcard; -use failure::Error; -use failure::Fallible as Result; -use failure::ResultExt; +use anyhow::Error; +use anyhow::Result; +use anyhow::Context; +use failure::Fail; use libimagstore::storeid::StoreId; use libimagstore::iter::Entries; @@ -153,11 +154,14 @@ impl<'a> ContactStore<'a> for Store { /// /// That means calculating the StoreId and the Value from the vcard data fn prepare_fetching_from_store(buf: &str) -> Result<(StoreId, Value)> { - let vcard = Vcard::build(&buf).context("Cannot parse Vcard").map_err(Error::from)?; + let vcard = Vcard::build(&buf) + .map_err(|e| e.compat()) + .map_err(Error::from) + .context("Cannot parse Vcard")?; debug!("Parsed: {:?}", vcard); let uid = vcard.uid() - .ok_or_else(|| format_err!("UID Missing: {}", buf.to_string()))?; + .ok_or_else(|| anyhow!("UID Missing: {}", buf.to_string()))?; let value = { // dirty ugly hack let serialized = DeserVcard::from(vcard); diff --git a/lib/domain/libimagcontact/src/util.rs b/lib/domain/libimagcontact/src/util.rs index 6ef5fdb1..cbe82378 100644 --- a/lib/domain/libimagcontact/src/util.rs +++ b/lib/domain/libimagcontact/src/util.rs @@ -22,7 +22,7 @@ use std::fmt::Debug; use std::fs::File; use std::io::Read; -use failure::Fallible as Result; +use anyhow::Result; pub fn read_to_string<A: AsRef<Path> + Debug>(pb: A) -> Result<String> { let mut cont = String::new(); diff --git a/lib/domain/libimagdiary/Cargo.toml b/lib/domain/libimagdiary/Cargo.toml index ef2ee3d2..b5c45a60 100644 --- a/lib/domain/libimagdiary/Cargo.toml +++ b/lib/domain/libimagdiary/Cargo.toml @@ -23,9 +23,9 @@ maintenance = { status = "actively-developed" } chrono = "0.4.7" log = "0.4.6" toml = "0.5.1" -toml-query = "0.9.2" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } itertools = "0.8.0" -failure = "0.1.5" +anyhow = "1" filters = "0.3.0" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } diff --git a/lib/domain/libimagdiary/src/diary.rs b/lib/domain/libimagdiary/src/diary.rs index 95dad9e7..5a30ebc6 100644 --- a/lib/domain/libimagdiary/src/diary.rs +++ b/lib/domain/libimagdiary/src/diary.rs @@ -29,9 +29,9 @@ use chrono::Datelike; use itertools::Itertools; use chrono::naive::NaiveDateTime; use chrono::Timelike; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; +use anyhow::Result; +use anyhow::Context; +use anyhow::Error; use crate::entry::IsDiaryEntry; use crate::diaryid::DiaryId; diff --git a/lib/domain/libimagdiary/src/diaryid.rs b/lib/domain/libimagdiary/src/diaryid.rs index 14c94f81..353a7c35 100644 --- a/lib/domain/libimagdiary/src/diaryid.rs +++ b/lib/domain/libimagdiary/src/diaryid.rs @@ -26,10 +26,10 @@ use chrono::naive::NaiveTime; use chrono::naive::NaiveDate; use chrono::Datelike; use chrono::Timelike; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; -use failure::err_msg; +use anyhow::Result; +use anyhow::Context; +use anyhow::Error; + use libimagstore::storeid::StoreId; use libimagstore::storeid::IntoStoreId; @@ -202,7 +202,7 @@ fn component_to_str<'a>(com: Component<'a>) -> Result<&'a str> { Component::Normal(s) => Some(s), _ => None, }.and_then(|s| s.to_str()) - .ok_or_else(|| err_msg("ID Parse error")) + .ok_or_else(|| anyhow!("ID Parse error")) } impl FromStoreId for DiaryId { @@ -215,7 +215,7 @@ impl FromStoreId for DiaryId { fn next_component<'a>(components: &'a mut Rev<Components>) -> Result<&'a str> { components.next() - .ok_or_else(|| err_msg("ID parse error")) + .ok_or_else(|| anyhow!("ID parse error")) .and_then(component_to_str) } @@ -235,7 +235,7 @@ impl FromStoreId for DiaryId { match (hour, minute, second) { (Some(h), Some(m), Some(s)) => Ok((h, m, s)), - _ => Err(err_msg("ID Parse error")), + _ => Err(anyhow!("ID Parse error")), } })?; @@ -244,7 +244,7 @@ impl FromStoreId for DiaryId { s.parse::<u32>() .context("Failed to parse day from u32") .map_err(Error::from) - .context(err_msg("ID parse error")) + .context(anyhow!("ID parse error")) .map_err(Error::from) }); @@ -253,7 +253,7 @@ impl FromStoreId for DiaryId { s.parse::<u32>() .context("Failed to parse month from u32") .map_err(Error::from) - .context(err_msg("ID Parse error")) + .context(anyhow!("ID Parse error")) .map_err(Error::from) }); @@ -262,7 +262,7 @@ impl FromStoreId for DiaryId { s.parse::<i32>() .context("Failed to parse year from i32") .map_err(Error::from) - .context(err_msg("ID Parse error")) + .context(anyhow!("ID Parse error")) .map_err(Error::from) }); diff --git a/lib/domain/libimagdiary/src/entry.rs b/lib/domain/libimagdiary/src/entry.rs index 7707fd2b..3e3df58a 100644 --- a/lib/domain/libimagdiary/src/entry.rs +++ b/lib/domain/libimagdiary/src/entry.rs @@ -21,7 +21,7 @@ use libimagstore::store::Entry; use libimagentryutil::isa::Is; use libimagentryutil::isa::IsKindHeaderPathProvider; -use failure::Fallible as Result; +use anyhow::Result; use crate::diaryid::DiaryId; use crate::diaryid::FromStoreId; diff --git a/lib/domain/libimagdiary/src/iter.rs b/lib/domain/libimagdiary/src/iter.rs index 6c43e75b..3d79b9e6 100644 --- a/lib/domain/libimagdiary/src/iter.rs +++ b/lib/domain/libimagdiary/src/iter.rs @@ -26,9 +26,9 @@ use libimagstore::storeid::StoreIdIterator; use libimagstore::storeid::StoreId; use crate::is_in_diary::IsInDiary; -use failure::Fallible as Result; +use anyhow::Result; + -use failure::err_msg; /// A iterator for iterating over diary entries pub struct DiaryEntryIterator { @@ -150,7 +150,7 @@ impl Iterator for DiaryNameIterator { s.split("diary/") .nth(1) .and_then(|n| n.split('/').nth(0).map(String::from)) - .ok_or_else(|| err_msg("Error finding diary name")) + .ok_or_else(|| anyhow!("Error finding diary name")) })); }, } diff --git a/lib/domain/libimagdiary/src/lib.rs b/lib/domain/libimagdiary/src/lib.rs index 11a21093..78c8cf4f 100644 --- a/lib/domain/libimagdiary/src/lib.rs +++ b/lib/domain/libimagdiary/src/lib.rs @@ -42,7 +42,7 @@ extern crate chrono; extern crate toml; extern crate toml_query; extern crate itertools; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate filters; #[macro_use] extern crate libimagstore; diff --git a/lib/domain/libimagdiary/src/viewer.rs b/lib/domain/libimagdiary/src/viewer.rs index 1a458a1c..c79e0483 100644 --- a/lib/domain/libimagdiary/src/viewer.rs +++ b/lib/domain/libimagdiary/src/viewer.rs @@ -22,14 +22,13 @@ use std::io::Write; use std::ops::Deref; -use failure::ResultExt; -use failure::err_msg; +use anyhow::Context; +use anyhow::Result; +use anyhow::Error; use libimagstore::store::Entry; use libimagentryview::viewer::Viewer; use libimagentryview::builtin::plain::PlainViewer; -use libimagentryview::error::Error; -use libimagentryview::error::Result; use crate::entry::DiaryEntry; /// This viewer does _not_ implement libimagentryview::viewer::Viewer because we need to be able to @@ -71,7 +70,7 @@ impl Viewer for DiaryViewer { e.deref() .diary_id() .map(|id| (id, e)) - .context(err_msg("View error")) + .context(anyhow!("View error")) .map_err(Error::from) }) .collect::<Result<Vec<_>>>()?; diff --git a/lib/domain/libimaghabit/Cargo.toml b/lib/domain/libimaghabit/Cargo.toml index d1d609ff..b12d03e4 100644 --- a/lib/domain/libimaghabit/Cargo.toml +++ b/lib/domain/libimaghabit/Cargo.toml @@ -23,9 +23,9 @@ maintenance = { status = "actively-developed" } chrono = "0.4.7" log = "0.4.6" toml = "0.5.1" -toml-query = "0.9.2" -kairos = "0.3.0" -failure = "0.1.5" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } +kairos = { git = "https://github.com/matthiasbeyer/kairos", branch = "master" } +anyhow = "1" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } diff --git a/lib/domain/libimaghabit/src/habit.rs b/lib/domain/libimaghabit/src/habit.rs index ef6bcd51..3b0dec4d 100644 --- a/lib/domain/libimaghabit/src/habit.rs +++ b/lib/domain/libimaghabit/src/habit.rs @@ -23,10 +23,10 @@ use toml_query::insert::TomlValueInsertExt; use chrono::NaiveDateTime; use chrono::Local; use chrono::NaiveDate; -use failure::Error; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::err_msg; +use anyhow::Error; +use anyhow::Result; +use anyhow::Context; + use crate::iter::HabitInstanceStoreIdIterator; use crate::util::IsHabitCheck; @@ -146,7 +146,7 @@ impl HabitTemplate for Entry { match parse(&r)? { Parsed::TimeType(tt) => Ok(tt), Parsed::Iterator(_) => { - Err(format_err!("'{}' yields an iterator. Cannot use.", r)) + Err(anyhow!("'{}' yields an iterator. Cannot use.", r)) }, } }; @@ -164,7 +164,7 @@ impl HabitTemplate for Entry { .calculate()? .get_moment() .map(Clone::clone) - .ok_or_else(|| err_msg("until-date seems to have non-date value")) + .ok_or_else(|| anyhow!("until-date seems to have non-date value")) }); debug!("Until-Date is {:?}", basedate); @@ -187,7 +187,7 @@ impl HabitTemplate for Entry { } } } else { - return Err(err_msg("Iterator seems to return bogus values.")); + return Err(anyhow!("Iterator seems to return bogus values.")); } } @@ -257,7 +257,7 @@ impl HabitTemplate for Entry { fn instance_id_for_name_and_datestr(habit_name: &str, habit_date: &str) -> Result<StoreId> { crate::module_path::new_id(format!("instance/{}-{}", habit_name, habit_date)) - .context(format_err!("Failed building ID for instance: habit name = {}, habit date = {}", habit_name, habit_date)) + .context(anyhow!("Failed building ID for instance: habit name = {}, habit date = {}", habit_name, habit_date)) .map_err(Error::from) } @@ -271,9 +271,9 @@ pub mod builder { use libimagstore::store::FileLockEntry; use libimagentryutil::isa::Is; - use failure::Error; - use failure::Fallible as Result; - use failure::err_msg; + use anyhow::Error; + use anyhow::Result; + use libimagutil::date::date_to_string; use crate::habit::IsHabitTemplate; @@ -317,7 +317,7 @@ pub mod builder { pub fn build<'a>(self, store: &'a Store) -> Result<FileLockEntry<'a>> { #[inline] fn mkerr(s: &'static str) -> Error { - format_err!("Habit builder missing: {}", s) + anyhow!("Habit builder missing: {}", s) } let name = self.name.ok_or_else(|| mkerr("name"))?; @@ -332,7 +332,7 @@ pub mod builder { if let Some(until) = self.untildate { debug!("Success: Until-Date present"); if dateobj > until { - let e = err_msg("Habit builder logic error: until-date before start date"); + let e = anyhow!("Habit builder logic error: until-date before start date"); return Err(e); } } diff --git a/lib/domain/libimaghabit/src/instance.rs b/lib/domain/libimaghabit/src/instance.rs index 89d6b377..65bba59d 100644 --- a/lib/domain/libimaghabit/src/instance.rs +++ b/lib/domain/libimaghabit/src/instance.rs @@ -22,7 +22,7 @@ use std::ops::Deref; use chrono::NaiveDate; use toml::Value; use toml_query::set::TomlValueSetExt; -use failure::Fallible as Result; +use anyhow::Result; use crate::util::*; use crate::habit::HabitTemplate; @@ -94,7 +94,7 @@ impl HabitInstance for Entry { let templ_name = self.get_template_name()?; for link in self.links()? { let template = store.get(link.get_store_id().clone())?.ok_or_else(|| { - format_err!("Entry {} is linked to {}, but that entry does not exist", + anyhow!("Entry {} is linked to {}, but that entry does not exist", self.get_location(), link.get_store_id()) })?; @@ -102,7 +102,7 @@ impl HabitInstance for Entry { return template.habit_comment() } } - Err(format_err!("Cannot find template entry for {}", self.get_location())) + Err(anyhow!("Cannot find template entry for {}", self.get_location())) } fn get_template_name(&self) -> Result<String> { diff --git a/lib/domain/libimaghabit/src/iter.rs b/lib/domain/libimaghabit/src/iter.rs index d09efc2d..680f08e0 100644 --- a/lib/domain/libimaghabit/src/iter.rs +++ b/lib/domain/libimaghabit/src/iter.rs @@ -17,9 +17,9 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use failure::Error; -use failure::Fallible as Result; -use failure::ResultExt; +use anyhow::Error; +use anyhow::Result; +use anyhow::Context; use libimagstore::storeid::StoreIdIterator; use libimagstore::storeid::StoreIdIteratorWithStore; diff --git a/lib/domain/libimaghabit/src/lib.rs b/lib/domain/libimaghabit/src/lib.rs index 4317071d..6bef5e60 100644 --- a/lib/domain/libimaghabit/src/lib.rs +++ b/lib/domain/libimaghabit/src/lib.rs @@ -40,7 +40,7 @@ extern crate toml; extern crate toml_query; extern crate kairos; #[macro_use] extern crate log; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; #[macro_use] extern crate libimagstore; extern crate libimagerror; diff --git a/lib/domain/libimaghabit/src/store.rs b/lib/domain/libimaghabit/src/store.rs index 91de8f33..c49f9381 100644 --- a/lib/domain/libimaghabit/src/store.rs +++ b/lib/domain/libimaghabit/src/store.rs @@ -17,7 +17,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use failure::Fallible as Result; +use anyhow::Result; use crate::habit::builder::HabitBuilder; use crate::iter::HabitTemplateStoreIdIterator; diff --git a/lib/domain/libimaghabit/src/util.rs b/lib/domain/libimaghabit/src/util.rs index 81e64b29..3aca8b00 100644 --- a/lib/domain/libimaghabit/src/util.rs +++ b/lib/domain/libimaghabit/src/util.rs @@ -19,16 +19,16 @@ use std::ops::BitXor; -use failure::Error; -use failure::Fallible as Result; -use failure::ResultExt; +use anyhow::Error; +use anyhow::Result; +use anyhow::Context; use crate::habit::HabitTemplate; use crate::instance::HabitInstance; use libimagstore::storeid::StoreId; use libimagstore::store::Entry; -use libimagerror::errors::ErrorMsg as EM; +use libimagerror::errors::Error as EM; /// Helper trait to check whether a object which can be a habit instance and a habit template is /// actually a valid object, whereas "valid" is defined that it is _either_ an instance or a @@ -89,7 +89,7 @@ pub fn get_string_header_from_entry(e: &Entry, path: &'static str) -> Result<Str e.get_header() .read_string(path)? .ok_or_else(|| EM::EntryHeaderFieldMissing(path)) - .context(format_err!("Error while reading header '{}' from '{}'", path, e.get_location())) + .context(anyhow!("Error while reading header '{}' from '{}'", path, e.get_location())) .map_err(Error::from) } diff --git a/lib/domain/libimaglog/Cargo.toml b/lib/domain/libimaglog/Cargo.toml index 55b2409c..b68567f5 100644 --- a/lib/domain/libimaglog/Cargo.toml +++ b/lib/domain/libimaglog/Cargo.toml @@ -21,8 +21,8 @@ maintenance = { status = "actively-developed" } [dependencies] toml = "0.5.1" -toml-query = "0.9.2" -failure = "0.1.5" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } +anyhow = "1" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } diff --git a/lib/domain/libimaglog/src/lib.rs b/lib/domain/libimaglog/src/lib.rs index 78ceb152..995666fb 100644 --- a/lib/domain/libimaglog/src/lib.rs +++ b/lib/domain/libimaglog/src/lib.rs @@ -35,7 +35,7 @@ while_true, )] -extern crate failure; +extern crate anyhow; extern crate toml; extern crate toml_query; diff --git a/lib/domain/libimaglog/src/log.rs b/lib/domain/libimaglog/src/log.rs index be38d9f4..29561a36 100644 --- a/lib/domain/libimaglog/src/log.rs +++ b/lib/domain/libimaglog/src/log.rs @@ -22,9 +22,9 @@ use libimagstore::store::Entry; use libimagentryutil::isa::Is; use libimagentryutil::isa::IsKindHeaderPathProvider; -use failure::Fallible as Result; -use failure::Error; -use failure::ResultExt; +use anyhow::Result; +use anyhow::Error; +use anyhow::Context; use toml::Value; diff --git a/lib/domain/libimagmail/Cargo.toml b/lib/domain/libimagmail/Cargo.toml index e0b1a891..f4a1cb82 100644 --- a/lib/domain/libimagmail/Cargo.toml +++ b/lib/domain/libimagmail/Cargo.toml @@ -22,10 +22,10 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.6" toml = "0.5.1" -toml-query = "0.9.2" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } mailparse = "0.8.0" filters = "0.3.0" -failure = "0.1.5" +anyhow = "1" resiter = "0.4.0" serde = "1.0.94" serde_derive = "1.0.94" diff --git a/lib/domain/libimagmail/src/fetch.rs b/lib/domain/libimagmail/src/fetch.rs index fa7106d5..72f5d32c 100644 --- a/lib/domain/libimagmail/src/fetch.rs +++ b/lib/domain/libimagmail/src/fetch.rs @@ -71,7 +71,7 @@ impl MailFetcher { let account = config .account(self.account_name_to_fetch) - .ok_or_else(|| format_err!("Account '{}' does not exist", self.account_name_to_fetch))?; + .ok_or_else(|| anyhow!("Account '{}' does not exist", self.account_name_to_fetch))?; if fetchcommand.contains(" ") { // error on whitespace in command diff --git a/lib/domain/libimagmail/src/hasher.rs b/lib/domain/libimagmail/src/hasher.rs index 2ecbc7b1..7fed9514 100644 --- a/lib/domain/libimagmail/src/hasher.rs +++ b/lib/domain/libimagmail/src/hasher.rs @@ -19,7 +19,7 @@ use std::path::Path; -use failure::Fallible as Result; +use anyhow::Result; use libimagentryref::hasher::Hasher; diff --git a/lib/domain/libimagmail/src/iter.rs b/lib/domain/libimagmail/src/iter.rs index bba6b690..f1bb11a0 100644 --- a/lib/domain/libimagmail/src/iter.rs +++ b/lib/domain/libimagmail/src/iter.rs @@ -17,10 +17,10 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; -use failure::err_msg; +use anyhow::Result; +use anyhow::Context; +use anyhow::Error; + use libimagstore::iter::get::StoreGetIterator; use libimagstore::store::FileLockEntry; @@ -70,7 +70,7 @@ impl<'a> Iterator for MailIterator<'a> { Ok(None) => if self.ignore_ungetable { continue } else { - return Some(Err(err_msg("Failed to get one entry"))) + return Some(Err(anyhow!("Failed to get one entry"))) }, Err(e) => return Some(Err(e)), diff --git a/lib/domain/libimagmail/src/lib.rs b/lib/domain/libimagmail/src/lib.rs index 913acfc9..65ea418c 100644 --- a/lib/domain/libimagmail/src/lib.rs +++ b/lib/domain/libimagmail/src/lib.rs @@ -42,7 +42,7 @@ extern crate mailparse; extern crate toml; extern crate toml_query; extern crate filters; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate resiter; extern crate serde; #[macro_use] extern crate serde_derive; diff --git a/lib/domain/libimagmail/src/mail.rs b/lib/domain/libimagmail/src/mail.rs index f24f5506..d26346dd 100644 --- a/lib/domain/libimagmail/src/mail.rs +++ b/lib/domain/libimagmail/src/mail.rs @@ -19,9 +19,9 @@ use std::str::FromStr; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; +use anyhow::Result; +use anyhow::Context; +use anyhow::Error; use toml_query::read::TomlValueReadExt; use resiter::Filter; @@ -81,12 +81,12 @@ impl Mail for Entry { let mail_file_location = self.as_ref_with_hasher::<MailHasher>().get_path(refconfig)?; match ::mailparse::parse_mail(read_to_string(mail_file_location.as_path())?.as_bytes()) - .context(format_err!("Cannot parse Email {}", mail_file_location.display()))? + .context(anyhow!("Cannot parse Email {}", mail_file_location.display()))? .headers .into_iter() .filter_map(|hdr| { match hdr.get_key() - .context(format_err!("Cannot fetch key '{}' from Email {}", field, mail_file_location.display())) + .context(anyhow!("Cannot fetch key '{}' from Email {}", field, mail_file_location.display())) .map_err(Error::from) { Ok(k) => if k == field { @@ -140,7 +140,7 @@ impl Mail for Entry { fn get_message_id(&self, refconfig: &RefConfig) -> Result<Option<MessageId>> { if let Some(s) = self.get_header().read("mail.message-id")? { let s = s.as_str() - .ok_or_else(|| format_err!("'mail.message-id' is not a String in {}", self.get_location()))?; + .ok_or_else(|| anyhow!("'mail.message-id' is not a String in {}", self.get_location()))?; Ok(Some(MessageId::from(String::from(s)))) } else { self.get_field(refconfig, "Message-ID") @@ -163,18 +163,18 @@ impl Mail for Entry { let path = self.as_ref_with_hasher::<MailHasher>().get_path(refconfig)?; if !path.exists() { - return Err(format_err!("Path {} does not exist", path.display())) + return Err(anyhow!("Path {} does not exist", path.display())) } { // Now parse mail flags path.to_str() - .ok_or_else(|| format_err!("Path is not UTF-8: {}", path.display()))? + .ok_or_else(|| anyhow!("Path is not UTF-8: {}", path.display()))? .split("2,") .map(String::from) .collect::<Vec<String>>() .split_last() - .ok_or_else(|| format_err!("Splitting path into prefix and flags failed: {}", path.display()))? + .ok_or_else(|| anyhow!("Splitting path into prefix and flags failed: {}", path.display()))? .0 .chars() .map(|c| c.to_string()) @@ -289,7 +289,7 @@ impl Mail for Entry { trace!("Fetching {}", n); // Get the FileLockEntry for the StoreId, or fail if it cannot be found - let next_entry = store.get(n.clone())?.ok_or_else(|| format_err!("Cannot find {}", n))?; + let next_entry = store.get(n.clone())?.ok_or_else(|| anyhow!("Cannot find {}", n))?; // if the FileLockEntry is a Mail if next_entry.is_mail()? { @@ -334,7 +334,7 @@ impl<'a> MailHeader<'a> { .iter() .filter_map(|hdr| { match hdr.get_key() - .context(format_err!("Cannot get field {}", field)) + .context(anyhow!("Cannot get field {}", field)) .map_err(Error::from) { Ok(key) => if key == field { diff --git a/lib/domain/libimagmail/src/mailflags.rs b/lib/domain/libimagmail/src/mailflags.rs index 5fd52761..5d50d35b 100644 --- a/lib/domain/libimagmail/src/mailflags.rs +++ b/lib/domain/libimagmail/src/mailflags.rs @@ -20,8 +20,8 @@ use std::fmt::{Display, Result as FmtResult, Formatter}; use std::str::FromStr; -use failure::Fallible as Result; -use failure::Error; +use anyhow::Result; +use anyhow::Error; /// Message flags /// @@ -71,7 +71,7 @@ impl FromStr for MailFlag { "T" => Ok(MailFlag::Trashed), "D" => Ok(MailFlag::Draft), "F" => Ok(MailFlag::Flagged), - _ => Err(format_err!("Unknown message flag: '{}'", s)), + _ => Err(anyhow!("Unknown message flag: '{}'", s)), } } } diff --git a/lib/domain/libimagmail/src/send.rs b/lib/domain/libimagmail/src/send.rs index 6c5575f0..0c458bc8 100644 --- a/lib/domain/libimagmail/src/send.rs +++ b/lib/domain/libimagmail/src/send.rs @@ -58,7 +58,7 @@ impl MailSender { let account = config .account(self.account_name_to_send_with) - .ok_or_else(|| format_err!("Account '{}' does not exist", self.account_name_to_send_with))?; + .ok_or_else(|| anyhow!("Account '{}' does not exist", self.account_name_to_send_with))?; if sendcommand.contains(" ") { // error on whitespace in command @@ -73,7 +73,7 @@ impl MailSender { let outgoingbox = account .outgoingbox .to_str() - .ok_or_else(|| format_err!("Cannot use '{:?}' as outgoingbox", account.outgoingbox))?; + .ok_or_else(|| anyhow!("Cannot use '{:?}' as outgoingbox", account.outgoingbox))?; let mut output = Command::new(sendcommand) // TODO: Add argument support diff --git a/lib/domain/libimagmail/src/store.rs b/lib/domain/libimagmail/src/store.rs index 8b0200e1..72d1e95d 100644 --- a/lib/domain/libimagmail/src/store.rs +++ b/lib/domain/libimagmail/src/store.rs @@ -21,7 +21,7 @@ use std::path::Path; use std::path::PathBuf; use std::fmt::Debug; -use failure::Fallible as Result; +use anyhow::Result; use toml::Value; use toml_query::insert::TomlValueInsertExt; @@ -97,11 +97,11 @@ impl<'a> MailStore<'a> for Store { match self.get(new_sid)? { Some(mut entry) => { if !entry.is_ref()? { - return Err(format_err!("{} is not a ref", entry.get_location())) + return Err(anyhow!("{} is not a ref", entry.get_location())) } if p.as_ref().ends_with(entry.as_ref_with_hasher::<MailHasher>().get_relative_path()?) { - return Err(format_err!("{} is not a ref to {:?}", + return Err(anyhow!("{} is not a ref to {:?}", entry.get_location(), p.as_ref().display())) } @@ -142,7 +142,7 @@ impl<'a> MailStore<'a> for Store { Some(e) => if e.is_mail()? { Ok(Some(e)) } else { - Err(format_err!("{} is not a mail entry", e.get_location())) + Err(anyhow!("{} is not a mail entry", e.get_location())) }, None => Ok(None) }) diff --git a/lib/domain/libimagmail/src/util.rs b/lib/domain/libimagmail/src/util.rs index 853f4626..8fd275fb 100644 --- a/lib/domain/libimagmail/src/util.rs +++ b/lib/domain/libimagmail/src/util.rs @@ -21,9 +21,9 @@ use std::path::Path; use std::fs::OpenOptions; use std::io::Read; -use failure::Error; -use failure::Fallible as Result; -use failure::ResultExt; +use anyhow::Error; +use anyhow::Result; +use anyhow::Context; use crate::mid::MessageId; @@ -49,7 +49,7 @@ pub(crate) fn get_message_header_at_key<P: AsRef<Path>, K: AsRef<str>>(p: P, k: }; ::mailparse::parse_mail(&buffer) - .context(format_err!("Cannot parse Email {}", p.as_ref().display()))? + .context(anyhow!("Cannot parse Email {}", p.as_ref().display()))? .headers .into_iter() .filter_map(|hdr| match hdr.get_key().context("Cannot get key from mail header").map_err(Error::from) { @@ -65,7 +65,7 @@ pub(crate) fn get_message_header_at_key<P: AsRef<Path>, K: AsRef<str>>(p: P, k: Err(e) => Some(Err(e)) }) .next() - .ok_or_else(|| format_err!("'{}' not found in {}", k.as_ref(), p.as_ref().display()))? + .ok_or_else(|| anyhow!("'{}' not found in {}", k.as_ref(), p.as_ref().display()))? .and_then(|hdr| hdr.get_value().context("Cannot get value from mail header").map_err(Error::from)) } @@ -88,7 +88,7 @@ pub(crate) fn strip_message_delimiters<ID: AsRef<str>>(id: ID) -> String { pub fn get_mail_text_content<P: AsRef<Path>>(p: P) -> Result<String> { ::mailparse::parse_mail(::std::fs::read_to_string(p.as_ref())?.as_bytes()) - .context(format_err!("Cannot parse Email {}", p.as_ref().display()))? + .context(anyhow!("Cannot parse Email {}", p.as_ref().display()))? .get_body() .context("Cannot get body of mail") .map_err(Error::from) diff --git a/lib/domain/libimagnotes/Cargo.toml b/lib/domain/libimagnotes/Cargo.toml index 6c759155..c331672a 100644 --- a/lib/domain/libimagnotes/Cargo.toml +++ b/lib/domain/libimagnotes/Cargo.toml @@ -22,8 +22,8 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.6" toml = "0.5.1" -toml-query = "0.9.2" -failure = "0.1.5" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } +anyhow = "1" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } diff --git a/lib/domain/libimagnotes/src/iter.rs b/lib/domain/libimagnotes/src/iter.rs index 889cbf16..8f180ce9 100644 --- a/lib/domain/libimagnotes/src/iter.rs +++ b/lib/domain/libimagnotes/src/iter.rs @@ -21,9 +21,9 @@ use libimagstore::storeid::StoreId; use libimagstore::storeid::StoreIdIterator; use crate::notestoreid::*; -use failure::Fallible as Result; -use failure::Error; -use failure::ResultExt; +use anyhow::Result; +use anyhow::Error; +use anyhow::Context; #[derive(Debug)] pub struct NoteIterator(StoreIdIterator); diff --git a/lib/domain/libimagnotes/src/lib.rs b/lib/domain/libimagnotes/src/lib.rs index 2599ea8e..1fdd1a86 100644 --- a/lib/domain/libimagnotes/src/lib.rs +++ b/lib/domain/libimagnotes/src/lib.rs @@ -40,7 +40,7 @@ #[macro_use] extern crate log; extern crate toml; extern crate toml_query; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate libimagrt; #[macro_use] extern crate libimagstore; diff --git a/lib/domain/libimagnotes/src/note.rs b/lib/domain/libimagnotes/src/note.rs index 37da36b6..cb8d55f8 100644 --- a/lib/domain/libimagnotes/src/note.rs +++ b/lib/domain/libimagnotes/src/note.rs @@ -20,14 +20,14 @@ use toml::Value; use libimagstore::store::Entry; -use libimagerror::errors::ErrorMsg as EM; +use libimagerror::errors::Error as EM; use toml_query::read::TomlValueReadTypeExt; use toml_query::set::TomlValueSetExt; -use failure::Fallible as Result; -use failure::Error; -use failure::ResultExt; +use anyhow::Result; +use anyhow::Error; +use anyhow::Context; pub trait Note { fn set_name(&mut self, n: String) -> Result<()>; @@ -41,7 +41,7 @@ impl Note for Entry { fn set_name(&mut self, n: String) -> Result<()> { self.get_header_mut() .set("note.name", Value::String(n)) - .context(format_err!("Cannot set 'note.name' in header of {}", self.get_location())) + .context(anyhow!("Cannot set 'note.name' in header of {}", self.get_location())) .map_err(Error::from) .map(|_| ()) } diff --git a/lib/domain/libimagnotes/src/notestore.rs b/lib/domain/libimagnotes/src/notestore.rs index 5dec3a61..7fcb84fd 100644 --- a/lib/domain/libimagnotes/src/notestore.rs +++ b/lib/domain/libimagnotes/src/notestore.rs @@ -23,7 +23,7 @@ use libimagstore::store::FileLockEntry; use libimagstore::store::Store; use toml_query::insert::TomlValueInsertExt; -use failure::Fallible as Result; +use anyhow::Result; use crate::iter::*; diff --git a/lib/domain/libimagtimetrack/Cargo.toml b/lib/domain/libimagtimetrack/Cargo.toml index f8560f35..a0b20ac6 100644 --- a/lib/domain/libimagtimetrack/Cargo.toml +++ b/lib/domain/libimagtimetrack/Cargo.toml @@ -23,10 +23,10 @@ maintenance = { status = "actively-developed" } filters = "0.3.0" chrono = "0.4.7" toml = "0.5.1" -toml-query = "0.9.2" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } lazy_static = "1.3.0" is-match = "0.1.0" -failure = "0.1.5" +anyhow = "1" libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } diff --git a/lib/domain/libimagtimetrack/src/iter/create.rs b/lib/domain/libimagtimetrack/src/iter/create.rs index 8863af11..3338df89 100644 --- a/lib/domain/libimagtimetrack/src/iter/create.rs +++ b/lib/domain/libimagtimetrack/src/iter/create.rs @@ -20,9 +20,9 @@ use toml::Value; use toml_query::insert::TomlValueInsertExt; use chrono::naive::NaiveDateTime as NDT; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; +use anyhow::Result; +use anyhow::Context; +use anyhow::Error; use crate::constants::*; use crate::iter::storeid::TagStoreIdIter; diff --git a/lib/domain/libimagtimetrack/src/iter/get.rs b/lib/domain/libimagtimetrack/src/iter/get.rs index a797df35..044a0adc 100644 --- a/lib/domain/libimagtimetrack/src/iter/get.rs +++ b/lib/domain/libimagtimetrack/src/iter/get.rs @@ -21,7 +21,7 @@ use libimagstore::iter::Entries; use libimagstore::store::Store; use libimagstore::store::FileLockEntry; -use failure::Fallible as Result; +use anyhow::Result; use crate::constants::*; diff --git a/lib/domain/libimagtimetrack/src/iter/setendtime.rs b/lib/domain/libimagtimetrack/src/iter/setendtime.rs index 25b9330c..0434a334 100644 --- a/lib/domain/libimagtimetrack/src/iter/setendtime.rs +++ b/lib/domain/libimagtimetrack/src/iter/setendtime.rs @@ -20,7 +20,7 @@ use toml::Value; use toml_query::insert::TomlValueInsertExt; use chrono::naive::NaiveDateTime as NDT; -use failure::Fallible as Result; +use anyhow::Result; use crate::constants::*; use crate::iter::create::CreateTimeTrackIter; diff --git a/lib/domain/libimagtimetrack/src/iter/storeid.rs b/lib/domain/libimagtimetrack/src/iter/storeid.rs index afc34ede..5797c482 100644 --- a/lib/domain/libimagtimetrack/src/iter/storeid.rs +++ b/lib/domain/libimagtimetrack/src/iter/storeid.rs @@ -18,8 +18,8 @@ // use chrono::naive::NaiveDateTime as NDT; -use failure::Fallible as Result; -use failure::Error; +use anyhow::Result; +use anyhow::Error; use crate::constants::*; use crate::iter::tag::TagIter; diff --git a/lib/domain/libimagtimetrack/src/iter/tag.rs b/lib/domain/libimagtimetrack/src/iter/tag.rs index a37a38be..d6f97776 100644 --- a/lib/domain/libimagtimetrack/src/iter/tag.rs +++ b/lib/domain/libimagtimetrack/src/iter/tag.rs @@ -18,9 +18,9 @@ // use chrono::naive::NaiveDateTime as NDT; -use failure::Fallible as Result; +use anyhow::Result; + -use failure::err_msg; use crate::tag::TimeTrackingTag as TTT; use crate::iter::storeid::TagStoreIdIter; @@ -48,7 +48,7 @@ impl Iterator for TagIter { .map(|t| if is_tag_str(&t).is_ok() { Ok(TTT::from(t)) } else { - Err(err_msg("Error in Tag format")) + Err(anyhow!("Error in Tag format")) }) } } diff --git a/lib/domain/libimagtimetrack/src/lib.rs b/lib/domain/libimagtimetrack/src/lib.rs index 90a77aa3..763f15aa 100644 --- a/lib/domain/libimagtimetrack/src/lib.rs +++ b/lib/domain/libimagtimetrack/src/lib.rs @@ -45,7 +45,7 @@ extern crate toml_query; extern crate lazy_static; #[macro_use] extern crate is_match; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; #[macro_use] extern crate libimagstore; #[macro_use] extern crate libimagentryutil; diff --git a/lib/domain/libimagtimetrack/src/store.rs b/lib/domain/libimagtimetrack/src/store.rs index cab61ec2..20ffefcf 100644 --- a/lib/domain/libimagtimetrack/src/store.rs +++ b/lib/domain/libimagtimetrack/src/store.rs @@ -25,9 +25,9 @@ use chrono::NaiveDateTime as NDT; use toml::Value; use toml_query::insert::TomlValueInsertExt; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; +use anyhow::Result; +use anyhow::Context; +use anyhow::Error; use libimagstore::store::Store; use libimagstore::store::FileLockEntry; @@ -72,7 +72,7 @@ impl<'a> TimeTrackStore<'a> for Store { use std::path::PathBuf; COMPILER.compile(CRATE_NAME, start) - .context(format_err!("Failed to compile DatePath for crate '{}' with start = '{}'", + .context(anyhow!("Failed to compile DatePath for crate '{}' with start = '{}'", CRATE_NAME, start)) .map_err(Error::from) .map(|mut id| { diff --git a/lib/domain/libimagtimetrack/src/tag.rs b/lib/domain/libimagtimetrack/src/tag.rs index cbe8b7be..85d13a51 100644 --- a/lib/domain/libimagtimetrack/src/tag.rs +++ b/lib/domain/libimagtimetrack/src/tag.rs @@ -23,7 +23,7 @@ use std::fmt::Formatter; use std::path::PathBuf; use std::result::Result as RResult; -use failure::Fallible as Result; +use anyhow::Result; use libimagstore::storeid::IntoStoreId; use libimagstore::storeid::StoreId; diff --git a/lib/domain/libimagtimetrack/src/timetracking.rs b/lib/domain/libimagtimetrack/src/timetracking.rs index 93fe9b02..dbe73d06 100644 --- a/lib/domain/libimagtimetrack/src/timetracking.rs +++ b/lib/domain/libimagtimetrack/src/timetracking.rs @@ -27,7 +27,7 @@ use chrono::naive::NaiveDateTime; use libimagstore::store::Entry; -use libimagerror::errors::ErrorMsg as EM; +use libimagerror::errors::Error as EM; use libimagentryutil::isa::Is; use libimagentryutil::isa::IsKindHeaderPathProvider; @@ -38,9 +38,9 @@ use toml::Value; use toml_query::delete::TomlValueDeleteExt; use toml_query::insert::TomlValueInsertExt; use toml_query::read::TomlValueReadTypeExt; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; +use anyhow::Result; +use anyhow::Context; +use anyhow::Error; provide_kindflag_path!(pub IsTimeTracking, "timetrack.is_timetracking"); @@ -75,7 +75,7 @@ impl TimeTracking for Entry { fn get_timetrack_tag(&self) -> Result<TTT> { self.get_header() .read_string(DATE_TIME_TAG_HEADER_PATH) - .context(format_err!("Failed to read header '{}' of {}", DATE_TIME_TAG_HEADER_PATH, + .context(anyhow!("Failed to read header '{}' of {}", DATE_TIME_TAG_HEADER_PATH, self.get_location())) .map_err(Error::from)? .ok_or_else(|| Error::from(EM::EntryHeaderReadError)) @@ -87,7 +87,7 @@ impl TimeTracking for Entry { self.get_header_mut() .insert(DATE_TIME_START_HEADER_PATH, Value::String(s)) - .context(format_err!("Failed get header '{}' of {}", DATE_TIME_START_HEADER_PATH, + .context(anyhow!("Failed get header '{}' of {}", DATE_TIME_START_HEADER_PATH, self.get_location())) .map_err(Error::from) .map(|_| ()) @@ -96,7 +96,7 @@ impl TimeTracking for Entry { fn get_start_datetime(&self) -> Result<Option<NaiveDateTime>> { self.get_header() .read_string(DATE_TIME_START_HEADER_PATH) - .context(format_err!("Failed read header '{}' of {}", DATE_TIME_START_HEADER_PATH, + .context(anyhow!("Failed read header '{}' of {}", DATE_TIME_START_HEADER_PATH, self.get_location())) .map_err(Error::from) .and_then(header_value_to_dt) @@ -105,7 +105,7 @@ impl TimeTracking for Entry { fn delete_start_datetime(&mut self) -> Result<()> { self.get_header_mut() .delete(DATE_TIME_START_HEADER_PATH) - .context(format_err!("Failed delete header '{}' of {}", DATE_TIME_START_HEADER_PATH, + .context(anyhow!("Failed delete header '{}' of {}", DATE_TIME_START_HEADER_PATH, self.get_location())) .map_err(Error::from) .map(|_| ()) @@ -116,7 +116,7 @@ impl TimeTracking for Entry { self.get_header_mut() .insert(DATE_TIME_END_HEADER_PATH, Value::String(s)) - .context(format_err!("Failed insert header '{}' in {}", DATE_TIME_END_HEADER_PATH, + .context(anyhow!("Failed insert header '{}' in {}", DATE_TIME_END_HEADER_PATH, self.get_location())) .map_err(Error::from) .map(|_| ()) @@ -125,7 +125,7 @@ impl TimeTracking for Entry { fn get_end_datetime(&self) -> Result<Option<NaiveDateTime>> { self.get_header() .read_string(DATE_TIME_END_HEADER_PATH) - .context(format_err!("Failed read header '{}' of {}", DATE_TIME_END_HEADER_PATH, + .context(anyhow!("Failed read header '{}' of {}", DATE_TIME_END_HEADER_PATH, self.get_location())) .map_err(Error::from) .and_then(header_value_to_dt) @@ -134,7 +134,7 @@ impl TimeTracking for Entry { fn delete_end_datetime(&mut self) -> Result<()> { self.get_header_mut() .delete(DATE_TIME_END_HEADER_PATH) - .context(format_err!("Failed delete header '{}' of {}", DATE_TIME_END_HEADER_PATH, + .context(anyhow!("Failed delete header '{}' of {}", DATE_TIME_END_HEADER_PATH, self.get_location())) .map_err(Error::from) .map(|_| ()) @@ -161,7 +161,7 @@ impl TimeTracking for Entry { fn header_value_to_dt(val: Option<String>) -> Result<Option<NaiveDateTime>> { match val { Some(ref s) => NaiveDateTime::parse_from_str(s, DATE_TIME_FORMAT) - .context(format_err!("Failed to parse '{}' datetime with format '{}'", + .context(anyhow!("Failed to parse '{}' datetime with format '{}'", s, DATE_TIME_FORMAT)) .map_err(Error::from).map(Some), None => Ok(None), diff --git a/lib/domain/libimagtodo/Cargo.toml b/lib/domain/libimagtodo/Cargo.toml index ace432dc..24f2ff37 100644 --- a/lib/domain/libimagtodo/Cargo.toml +++ b/lib/domain/libimagtodo/Cargo.toml @@ -20,7 +20,7 @@ is-it-maintained-open-issues = { repository = "matthiasbeyer/imag" } maintenance = { status = "actively-developed" } [dependencies] -failure = "0.1" +anyhow = "1" filters = "0.3" log = "0.4" serde = "1" @@ -34,7 +34,8 @@ libimagentryutil = { version = "0.10.0", path = "../../../lib/entry/libimagentr libimagutil = { version = "0.10.0", path = "../../../lib/etc/libimagutil" } [dependencies.toml-query] -version = "0.9" +git = "https://github.com/matthiasbeyer/toml-query" +branch = "master" default-features = false features = ["typed"] diff --git a/lib/domain/libimagtodo/src/builder.rs b/lib/domain/libimagtodo/src/builder.rs index a3d925b1..3a618b73 100644 --- a/lib/domain/libimagtodo/src/builder.rs +++ b/lib/domain/libimagtodo/src/builder.rs @@ -18,8 +18,8 @@ // use chrono::NaiveDateTime; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Result; + use toml_query::insert::TomlValueInsertExt; use uuid::Uuid; @@ -59,14 +59,14 @@ impl TodoBuilder { } pub fn build<'a>(self, store: &'a Store) -> Result<FileLockEntry<'a>> { - let uuid = self.uuid.ok_or_else(|| err_msg("Uuid missing"))?; - let status = self.status.ok_or_else(|| err_msg("Status missing"))?; + let uuid = self.uuid.ok_or_else(|| anyhow!("Uuid missing"))?; + let status = self.status.ok_or_else(|| anyhow!("Status missing"))?; if self.check_sanity { trace!("Checking sanity before creating todo"); if let Err(s) = date_sanity_check(self.scheduled.as_ref(), self.hidden.as_ref(), self.due.as_ref()) { trace!("Not sane."); - return Err(format_err!("{}", s)) + return Err(anyhow!("{}", s)) } } diff --git a/lib/domain/libimagtodo/src/entry.rs b/lib/domain/libimagtodo/src/entry.rs index 9f4667f8..096d0b39 100644 --- a/lib/domain/libimagtodo/src/entry.rs +++ b/lib/domain/libimagtodo/src/entry.rs @@ -22,9 +22,9 @@ use libimagentryutil::isa::IsKindHeaderPathProvider; use libimagstore::store::Entry; use libimagutil::date::datetime_from_string; -use failure::Fallible as Result; -use failure::Error; -use failure::ResultExt; +use anyhow::Result; +use anyhow::Error; +use anyhow::Context; use chrono::NaiveDateTime; use toml_query::read::Partial; use toml_query::read::TomlValueReadExt; @@ -126,7 +126,7 @@ fn get_header(entry: &Entry) -> Result<TodoHeader> { entry.get_header() .read_partial::<TodoHeader>()? .ok_or_else(|| { - format_err!("{} does not contain a TODO header", entry.get_location()) + anyhow!("{} does not contain a TODO header", entry.get_location()) }) } diff --git a/lib/domain/libimagtodo/src/iter.rs b/lib/domain/libimagtodo/src/iter.rs index 4f2c5807..47e19c3f 100644 --- a/lib/domain/libimagtodo/src/iter.rs +++ b/lib/domain/libimagtodo/src/iter.rs @@ -19,8 +19,8 @@ use std::result::Result as RResult; -use failure::Fallible as Result; -use failure::Error; +use anyhow::Result; +use anyhow::Error; use filters::failable::filter::FailableFilter; use libimagstore::store::FileLockEntry; diff --git a/lib/domain/libimagtodo/src/lib.rs b/lib/domain/libimagtodo/src/lib.rs index 62729cbe..3d728c12 100644 --- a/lib/domain/libimagtodo/src/lib.rs +++ b/lib/domain/libimagtodo/src/lib.rs @@ -26,7 +26,7 @@ extern crate uuid; extern crate filters; #[macro_use] extern crate serde_derive; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; #[macro_use] extern crate log; extern crate libimagerror; diff --git a/lib/domain/libimagtodo/src/status.rs b/lib/domain/libimagtodo/src/status.rs index c46d3be4..bcc2e283 100644 --- a/lib/domain/libimagtodo/src/status.rs +++ b/lib/domain/libimagtodo/src/status.rs @@ -19,7 +19,7 @@ use std::str::FromStr; -use failure::Fallible as Result; +use anyhow::Result; #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)] pub enum Status { @@ -44,14 +44,14 @@ impl Status { } impl FromStr for Status { - type Err = failure::Error; + type Err = anyhow::Error; fn from_str(s: &str) -> Result<Self> { match s { "pending" => Ok(Status::Pending), "done" => Ok(Status::Done), "deleted" => Ok(Status::Deleted), - other => Err(format_err!("{} is not a valid status", other)), + other => Err(anyhow!("{} is not a valid status", other)), } } } diff --git a/lib/domain/libimagtodo/src/store.rs b/lib/domain/libimagtodo/src/store.rs index df6ed0c0..34f6a09d 100644 --- a/lib/domain/libimagtodo/src/store.rs +++ b/lib/domain/libimagtodo/src/store.rs @@ -19,7 +19,7 @@ use std::result::Result as RResult; -use failure::Fallible as Result; +use anyhow::Result; use chrono::NaiveDateTime; use uuid::Uuid; diff --git a/lib/domain/libimagwiki/Cargo.toml b/lib/domain/libimagwiki/Cargo.toml index 9f69e94e..ecf68438 100644 --- a/lib/domain/libimagwiki/Cargo.toml +++ b/lib/domain/libimagwiki/Cargo.toml @@ -22,9 +22,9 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.6" toml = "0.5.1" -toml-query = "0.9.2" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } filters = "0.3.0" -failure = "0.1.5" +anyhow = "1" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } diff --git a/lib/domain/libimagwiki/src/entry.rs b/lib/domain/libimagwiki/src/entry.rs index b9f9049e..22a6809e 100644 --- a/lib/domain/libimagwiki/src/entry.rs +++ b/lib/domain/libimagwiki/src/entry.rs @@ -21,9 +21,9 @@ use libimagstore::store::Store; use libimagstore::store::Entry; use libimagentrymarkdown::processor::LinkProcessor; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; +use anyhow::Result; +use anyhow::Context; +use anyhow::Error; pub trait WikiEntry { fn autolink(&mut self, store: &Store) -> Result<()>; @@ -68,7 +68,7 @@ impl WikiEntry for Entry { /// See the documentation of `::libimagentrymarkdown::processor::LinkProcessor`. fn autolink_with_processor(&mut self, store: &Store, processor: LinkProcessor) -> Result<()> { processor.process(self, store) - .context(format_err!("Auto Link error: {}", self.get_location())) + .context(anyhow!("Auto Link error: {}", self.get_location())) .map_err(Error::from) } diff --git a/lib/domain/libimagwiki/src/lib.rs b/lib/domain/libimagwiki/src/lib.rs index 8f0d6b51..73d43674 100644 --- a/lib/domain/libimagwiki/src/lib.rs +++ b/lib/domain/libimagwiki/src/lib.rs @@ -41,7 +41,7 @@ extern crate filters; extern crate toml; extern crate toml_query; #[macro_use] extern crate log; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; #[macro_use] extern crate libimagstore; extern crate libimagerror; diff --git a/lib/domain/libimagwiki/src/store.rs b/lib/domain/libimagwiki/src/store.rs index e59f968a..57b4ea13 100644 --- a/lib/domain/libimagwiki/src/store.rs +++ b/lib/domain/libimagwiki/src/store.rs @@ -21,7 +21,7 @@ use libimagstore::store::FileLockEntry; use libimagstore::store::Store; use libimagstore::storeid::StoreId; -use failure::Fallible as Result; +use anyhow::Result; use crate::wiki::Wiki; diff --git a/lib/domain/libimagwiki/src/wiki.rs b/lib/domain/libimagwiki/src/wiki.rs index 30add13f..507b6344 100644 --- a/lib/domain/libimagwiki/src/wiki.rs +++ b/lib/domain/libimagwiki/src/wiki.rs @@ -24,10 +24,10 @@ use libimagstore::store::FileLockEntry; use libimagstore::iter::Entries; use libimagentrylink::linkable::Linkable; -use failure::Fallible as Result; -use failure::Error; -use failure::err_msg; -use failure::ResultExt; +use anyhow::Result; +use anyhow::Error; + +use anyhow::Context; pub struct Wiki<'a, 'b>(&'a Store, &'b str); @@ -61,7 +61,7 @@ impl<'a, 'b> Wiki<'a, 'b> { .get(sid) .context("Cannot get ID from store") .map_err(Error::from)? - .ok_or_else(|| err_msg("Missing index")) + .ok_or_else(|| anyhow!("Missing index")) } pub fn get_entry<EN: AsRef<str>>(&self, entry_name: EN) -> Result<Option<FileLockEntry<'a>>> { @@ -75,7 +75,7 @@ impl<'a, 'b> Wiki<'a, 'b> { let sid = crate::module_path::new_id(path)?; let mut index = self .get_entry("index")? - .ok_or_else(|| err_msg("Missing index page"))?; + .ok_or_else(|| anyhow!("Missing index page"))?; let mut entry = self.0.create(sid)?; entry.add_link(&mut index).map(|_| entry) @@ -86,7 +86,7 @@ impl<'a, 'b> Wiki<'a, 'b> { let sid = crate::module_path::new_id(path)?; let mut index = self .get_entry("index")? - .ok_or_else(|| err_msg("Missing index page"))?; + .ok_or_else(|| anyhow!("Missing index page"))?; let mut entry = self.0.retrieve(sid)?; entry.add_link(&mut index).map(|_| entry) diff --git a/lib/entry/libimagentryannotation/Cargo.toml b/lib/entry/libimagentryannotation/Cargo.toml index ee999344..1be867c1 100644 --- a/lib/entry/libimagentryannotation/Cargo.toml +++ b/lib/entry/libimagentryannotation/Cargo.toml @@ -22,9 +22,9 @@ maintenance = { status = "actively-developed" } [dependencies] lazy_static = "1.3.0" toml = "0.5.1" -toml-query = "0.9.2" -failure = "0.1.5" -failure_derive = "0.1.5" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } +anyhow = "1" + uuid = { version = "0.7.4", features = ["v4"] } log = "0.4.6" diff --git a/lib/entry/libimagentryannotation/src/annotateable.rs b/lib/entry/libimagentryannotation/src/annotateable.rs index 88a890cd..364c08a4 100644 --- a/lib/entry/libimagentryannotation/src/annotateable.rs +++ b/lib/entry/libimagentryannotation/src/annotateable.rs @@ -30,10 +30,10 @@ use libimagentryutil::isa::IsKindHeaderPathProvider; use toml_query::insert::TomlValueInsertExt; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; -use failure::err_msg; +use anyhow::Result; +use anyhow::Context; +use anyhow::Error; + pub trait Annotateable { fn annotate<'a>(&mut self, store: &'a Store) -> Result<FileLockEntry<'a>>; @@ -63,7 +63,7 @@ impl Annotateable for Entry { }) .and_then(|mut anno| { anno.add_link(self) - .context(err_msg("Linking error")) + .context(anyhow!("Linking error")) .map_err(Error::from) .map(|_| anno) }) @@ -78,7 +78,7 @@ impl Annotateable for Entry { Ok(Some(annotation)) } else { // error: annotation does not exist - Err(format_err!("Annotation '{}' does not exist", ann_name)).map_err(Error::from) + Err(anyhow!("Annotation '{}' does not exist", ann_name)).map_err(Error::from) } } diff --git a/lib/entry/libimagentryannotation/src/annotation_fetcher.rs b/lib/entry/libimagentryannotation/src/annotation_fetcher.rs index 400b6635..03f64ebc 100644 --- a/lib/entry/libimagentryannotation/src/annotation_fetcher.rs +++ b/lib/entry/libimagentryannotation/src/annotation_fetcher.rs @@ -20,7 +20,7 @@ use libimagstore::iter::Entries; use libimagstore::store::Store; -use failure::Fallible as Result; +use anyhow::Result; pub trait AnnotationFetcher<'a> { fn all_annotations(&'a self) -> Result<Entries<'a>>; diff --git a/lib/entry/libimagentryannotation/src/lib.rs b/lib/entry/libimagentryannotation/src/lib.rs index 82405bb7..7c44edd4 100644 --- a/lib/entry/libimagentryannotation/src/lib.rs +++ b/lib/entry/libimagentryannotation/src/lib.rs @@ -39,7 +39,7 @@ extern crate toml; extern crate toml_query; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; #[macro_use] extern crate log; extern crate uuid; diff --git a/lib/entry/libimagentrycategory/Cargo.toml b/lib/entry/libimagentrycategory/Cargo.toml index 65982cda..040820d9 100644 --- a/lib/entry/libimagentrycategory/Cargo.toml +++ b/lib/entry/libimagentrycategory/Cargo.toml @@ -22,8 +22,8 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.6" toml = "0.5.1" -toml-query = "0.9.2" -failure = "0.1.5" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } +anyhow = "1" libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } diff --git a/lib/entry/libimagentrycategory/src/category.rs b/lib/entry/libimagentrycategory/src/category.rs index bfd6bf17..a1ae139e 100644 --- a/lib/entry/libimagentrycategory/src/category.rs +++ b/lib/entry/libimagentrycategory/src/category.rs @@ -26,10 +26,10 @@ use libimagentrylink::linkable::Linkable; use toml_query::read::TomlValueReadTypeExt; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; -use failure::err_msg; +use anyhow::Result; +use anyhow::Context; +use anyhow::Error; + use crate::store::CATEGORY_REGISTER_NAME_FIELD_PATH; use crate::iter::CategoryEntryIterator; @@ -50,9 +50,9 @@ impl Category for Entry { trace!("Getting category name of '{:?}'", self.get_location()); self.get_header() .read_string(CATEGORY_REGISTER_NAME_FIELD_PATH) - .context(format_err!("Failed to read header at '{}'", CATEGORY_REGISTER_NAME_FIELD_PATH)) + .context(anyhow!("Failed to read header at '{}'", CATEGORY_REGISTER_NAME_FIELD_PATH)) .map_err(Error::from)? - .ok_or_else(|| err_msg("Category name missing")) + .ok_or_else(|| anyhow!("Category name missing")) } fn get_entries<'a>(&self, store: &'a Store) -> Result<CategoryEntryIterator<'a>> { diff --git a/lib/entry/libimagentrycategory/src/entry.rs b/lib/entry/libimagentrycategory/src/entry.rs index 25fde22b..c04e750d 100644 --- a/lib/entry/libimagentrycategory/src/entry.rs +++ b/lib/entry/libimagentrycategory/src/entry.rs @@ -24,12 +24,11 @@ use toml::Value; use libimagstore::store::Entry; use libimagentrylink::linkable::Linkable; -use libimagerror::errors::ErrorMsg as EM; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; -use failure::err_msg; +use anyhow::Result; +use anyhow::Context; +use anyhow::Error; + use crate::store::CategoryStore; pub trait EntryCategory { @@ -52,8 +51,7 @@ impl EntryCategory for Entry { trace!("Setting category '{}' UNCHECKED", s); self.get_header_mut() .insert(&String::from("category.value"), Value::String(s.to_string())) - .context(format_err!("Failed to insert header at 'category.value' of '{}'", self.get_location())) - .context(EM::EntryHeaderWriteError) + .context(anyhow!("Failed to insert header at 'category.value' of '{}'", self.get_location())) .map_err(Error::from) .map(|_| ()) } @@ -65,7 +63,7 @@ impl EntryCategory for Entry { trace!("Setting category '{}' checked", s); let mut category = register .get_category_by_name(s)? - .ok_or_else(|| err_msg("Category does not exist"))?; + .ok_or_else(|| anyhow!("Category does not exist"))?; self.set_category(s)?; self.add_link(&mut category)?; @@ -77,15 +75,14 @@ impl EntryCategory for Entry { trace!("Getting category from '{}'", self.get_location()); self.get_header() .read_string("category.value")? - .ok_or_else(|| err_msg("Category name missing")) + .ok_or_else(|| anyhow!("Category name missing")) } fn has_category(&self) -> Result<bool> { trace!("Has category? '{}'", self.get_location()); self.get_header() .read("category.value") - .context(format_err!("Failed to read header at 'category.value' of '{}'", self.get_location())) - .context(EM::EntryHeaderReadError) + .context(anyhow!("Failed to read header at 'category.value' of '{}'", self.get_location())) .map_err(Error::from) .map(|x| x.is_some()) } @@ -101,8 +98,7 @@ impl EntryCategory for Entry { self.get_header_mut() .delete("category.value") - .context(format_err!("Failed to delete header at 'category.value' of '{}'", self.get_location())) - .context(EM::EntryHeaderWriteError) + .context(anyhow!("Failed to delete header at 'category.value' of '{}'", self.get_location())) .map_err(Error::from) .map(|_| ()) } diff --git a/lib/entry/libimagentrycategory/src/iter.rs b/lib/entry/libimagentrycategory/src/iter.rs index cb09c0e3..8eac2d0a 100644 --- a/lib/entry/libimagentrycategory/src/iter.rs +++ b/lib/entry/libimagentrycategory/src/iter.rs @@ -23,10 +23,10 @@ use libimagstore::store::FileLockEntry; use toml_query::read::TomlValueReadTypeExt; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; -use failure::err_msg; +use anyhow::Result; +use anyhow::Context; +use anyhow::Error; + use crate::store::CATEGORY_REGISTER_NAME_FIELD_PATH; use crate::entry::EntryCategory; @@ -66,11 +66,11 @@ impl<'a> Iterator for CategoryNameIter<'a> { let func = |store: &Store| { // hack for returning Some(Result<_, _>) store .get(sid)? - .ok_or_else(|| err_msg("Store read error"))? + .ok_or_else(|| anyhow!("Store read error"))? .get_header() .read_string(query) - .context(format_err!("Failed to read header at '{}'", query))? - .ok_or_else(|| err_msg("Store read error")) + .context(anyhow!("Failed to read header at '{}'", query))? + .ok_or_else(|| anyhow!("Store read error")) .map_err(Error::from) }; @@ -103,7 +103,7 @@ impl<'a> Iterator for CategoryEntryIterator<'a> { let getter = |next| -> Result<(String, FileLockEntry<'a>)> { let entry = self.0 .get(next)? - .ok_or_else(|| err_msg("Store read error"))?; + .ok_or_else(|| anyhow!("Store read error"))?; Ok((entry.get_category()?, entry)) }; diff --git a/lib/entry/libimagentrycategory/src/lib.rs b/lib/entry/libimagentrycategory/src/lib.rs index 2d913f58..c2a1083b 100644 --- a/lib/entry/libimagentrycategory/src/lib.rs +++ b/lib/entry/libimagentrycategory/src/lib.rs @@ -41,7 +41,7 @@ extern crate toml_query; extern crate toml; #[macro_use] extern crate log; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate libimagerror; #[macro_use] extern crate libimagstore; diff --git a/lib/entry/libimagentrycategory/src/store.rs b/lib/entry/libimagentrycategory/src/store.rs index 59aea7ef..d7c8972e 100644 --- a/lib/entry/libimagentrycategory/src/store.rs +++ b/lib/entry/libimagentrycategory/src/store.rs @@ -25,12 +25,12 @@ use libimagstore::store::Store; use libimagstore::store::FileLockEntry; use libimagstore::storeid::StoreId; use libimagentryutil::isa::Is; -use libimagerror::errors::ErrorMsg as EM; +use libimagerror::errors::Error as EM; + +use anyhow::Result; +use anyhow::Context; +use anyhow::Error; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; -use failure::err_msg; use crate::iter::CategoryNameIter; use crate::category::IsCategory; @@ -92,7 +92,7 @@ impl CategoryStore for Store { { let mut category = self.get(sid.clone())? - .ok_or_else(|| err_msg("Category does not exist")) + .ok_or_else(|| anyhow!("Category does not exist")) .map_err(Error::from)?; for entry in category.get_entries(self)? { @@ -119,7 +119,7 @@ impl CategoryStore for Store { let sid = mk_category_storeid(name)?; self.get(sid) - .context(err_msg("Store write error")) + .context(anyhow!("Store write error")) .map_err(Error::from) } } @@ -208,24 +208,23 @@ mod tests { #[inline] fn mk_category_storeid(s: &str) -> Result<StoreId> { - crate::module_path::new_id(s).context(err_msg("Store id handling error")).map_err(Error::from) + crate::module_path::new_id(s).context(anyhow!("Store id handling error")).map_err(Error::from) } #[inline] fn represents_category(store: &Store, sid: StoreId, name: &str) -> Result<bool> { store.exists(sid.clone()) - .context(err_msg("Store id handling error")) + .context(anyhow!("Store id handling error")) .map_err(Error::from) .and_then(|bl| { if bl { store.get(sid) - .context(err_msg("Store read error")) + .context(anyhow!("Store read error")) .map_err(Error::from) .and_then(|fle| { if let Some(fle) = fle { fle.get_header() - .read_string(&String::from(CATEGORY_REGISTER_NAME_FIELD_PATH)) - .context(EM::EntryHeaderReadError)? + .read_string(&String::from(CATEGORY_REGISTER_NAME_FIELD_PATH))? .ok_or_else(|| Error::from(EM::EntryHeaderTypeError)) .map(|s| s == name) } else { diff --git a/lib/entry/libimagentrydatetime/Cargo.toml b/lib/entry/libimagentrydatetime/Cargo.toml index adc20c9e..40bef663 100644 --- a/lib/entry/libimagentrydatetime/Cargo.toml +++ b/lib/entry/libimagentrydatetime/Cargo.toml @@ -21,9 +21,9 @@ maintenance = { status = "actively-developed" } [dependencies] chrono = "0.4.7" -toml-query = "0.9.2" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } toml = "0.5.1" -failure = "0.1.5" +anyhow = "1" libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } diff --git a/lib/entry/libimagentrydatetime/src/datepath/compiler.rs b/lib/entry/libimagentrydatetime/src/datepath/compiler.rs index 9de7f88d..05d2b094 100644 --- a/lib/entry/libimagentrydatetime/src/datepath/compiler.rs +++ b/lib/entry/libimagentrydatetime/src/datepath/compiler.rs @@ -27,7 +27,7 @@ use libimagstore::storeid::StoreId; use crate::datepath::accuracy::Accuracy; use crate::datepath::format::Format; -use failure::Fallible as Result; +use anyhow::Result; pub struct DatePathCompiler { accuracy : Accuracy, diff --git a/lib/entry/libimagentrydatetime/src/datepath/to_store_id.rs b/lib/entry/libimagentrydatetime/src/datepath/to_store_id.rs index 8d1ca20c..145f424b 100644 --- a/lib/entry/libimagentrydatetime/src/datepath/to_store_id.rs +++ b/lib/entry/libimagentrydatetime/src/datepath/to_store_id.rs @@ -18,7 +18,7 @@ // use chrono::naive::NaiveDateTime; -use failure::Fallible as Result; +use anyhow::Result; use libimagstore::storeid::StoreId; use crate::datepath::compiler::DatePathCompiler; diff --git a/lib/entry/libimagentrydatetime/src/datetime.rs b/lib/entry/libimagentrydatetime/src/datetime.rs index 3c234154..886991a0 100644 --- a/lib/entry/libimagentrydatetime/src/datetime.rs +++ b/lib/entry/libimagentrydatetime/src/datetime.rs @@ -24,12 +24,12 @@ use toml_query::read::TomlValueReadTypeExt; use toml::Value; use libimagstore::store::Entry; -use libimagerror::errors::ErrorMsg as EM; +use libimagerror::errors::Error as EM; + +use anyhow::Error; +use anyhow::Result; +use anyhow::Context; -use failure::Error; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::err_msg; use crate::range::DateTimeRange; pub trait EntryDate { @@ -63,7 +63,7 @@ impl EntryDate for Entry { self.get_header() .read_string(&DATE_HEADER_LOCATION) .context("Error while reading date")? - .ok_or_else(|| err_msg("Error reading date"))? + .ok_or_else(|| anyhow!("Error reading date"))? .parse::<NaiveDateTime>() .context("Datetime parse error") .map_err(Error::from) @@ -90,7 +90,7 @@ impl EntryDate for Entry { self.get_header_mut() .insert(&DATE_HEADER_LOCATION, Value::String(date)) - .context(format_err!("Failed to insert header '{}' in '{}'", + .context(anyhow!("Failed to insert header '{}' in '{}'", DATE_HEADER_LOCATION, self.get_location())) .map_err(Error::from) @@ -132,14 +132,14 @@ impl EntryDate for Entry { .get_header() .read_string(&DATE_RANGE_START_HEADER_LOCATION) .context("Error while reading Datetime range")? - .ok_or_else(|| err_msg("Error reading date")) + .ok_or_else(|| anyhow!("Error reading date")) .and_then(str_to_ndt)?; let end = self .get_header() .read_string(&DATE_RANGE_START_HEADER_LOCATION) .context("Error reading Datetime range")? - .ok_or_else(|| err_msg("Error reading date")) + .ok_or_else(|| anyhow!("Error reading date")) .and_then(str_to_ndt)?; DateTimeRange::new(start, end) diff --git a/lib/entry/libimagentrydatetime/src/lib.rs b/lib/entry/libimagentrydatetime/src/lib.rs index d5ed7f15..17b6afa7 100644 --- a/lib/entry/libimagentrydatetime/src/lib.rs +++ b/lib/entry/libimagentrydatetime/src/lib.rs @@ -37,7 +37,7 @@ while_true, )] -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate chrono; extern crate toml_query; extern crate toml; diff --git a/lib/entry/libimagentrydatetime/src/range.rs b/lib/entry/libimagentrydatetime/src/range.rs index cd516454..451e858a 100644 --- a/lib/entry/libimagentrydatetime/src/range.rs +++ b/lib/entry/libimagentrydatetime/src/range.rs @@ -19,8 +19,8 @@ use chrono::naive::NaiveDateTime; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Result; + /// A Range between two dates #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -39,7 +39,7 @@ impl DateTimeRange { if start < end { Ok(DateTimeRange(start, end)) } else { - Err(err_msg("End date before start date")) + Err(anyhow!("End date before start date")) } } diff --git a/lib/entry/libimagentryedit/Cargo.toml b/lib/entry/libimagentryedit/Cargo.toml index 23e56f02..186759d5 100644 --- a/lib/entry/libimagentryedit/Cargo.toml +++ b/lib/entry/libimagentryedit/Cargo.toml @@ -22,7 +22,7 @@ maintenance = { status = "actively-developed" } [dependencies] error-chain = "0.12.1" toml = "0.5.1" -failure = "0.1.5" +anyhow = "1" libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" } diff --git a/lib/entry/libimagentryedit/src/edit.rs b/lib/entry/libimagentryedit/src/edit.rs index 1aafd2f1..e004a10f 100644 --- a/lib/entry/libimagentryedit/src/edit.rs +++ b/lib/entry/libimagentryedit/src/edit.rs @@ -20,12 +20,12 @@ use libimagrt::runtime::Runtime; use libimagstore::store::Entry; -use failure::Fallible as Result; -use failure::Error; -use failure::ResultExt; -use failure::err_msg; +use anyhow::Result; +use anyhow::Error; +use anyhow::Context; -use libimagerror::errors::ErrorMsg as EM; + +use libimagerror::errors::Error as EM; pub trait Edit { fn edit_content(&mut self, rt: &Runtime) -> Result<()>; @@ -78,11 +78,10 @@ pub fn edit_in_tmpfile(rt: &Runtime, s: &mut String) -> Result<()> { let editor = rt .editor() - .context(err_msg("No editor"))? - .ok_or_else(|| err_msg("No editor"))?; + .context(anyhow!("No editor"))? + .ok_or_else(|| anyhow!("No editor"))?; edit_in_tmpfile_with_command(editor, s) - .context(EM::IO) .map_err(Error::from) .and_then(|worked| if !worked { Err(Error::from(EM::ExternalProcessError)) diff --git a/lib/entry/libimagentryedit/src/lib.rs b/lib/entry/libimagentryedit/src/lib.rs index 37b576ba..16a6a750 100644 --- a/lib/entry/libimagentryedit/src/lib.rs +++ b/lib/entry/libimagentryedit/src/lib.rs @@ -42,6 +42,6 @@ extern crate libimagstore; extern crate libimagrt; extern crate libimagutil; extern crate toml; -extern crate failure; +#[macro_use] extern crate anyhow; pub mod edit; diff --git a/lib/entry/libimagentryfilter/Cargo.toml b/lib/entry/libimagentryfilter/Cargo.toml index 3388d5a7..e5d63e5e 100644 --- a/lib/entry/libimagentryfilter/Cargo.toml +++ b/lib/entry/libimagentryfilter/Cargo.toml @@ -26,9 +26,9 @@ log = "0.4.6" regex = "1.1.7" semver = "0.9.0" toml = "0.5.1" -toml-query = "0.9.2" -failure = "0.1.5" -failure_derive = "0.1.5" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } +anyhow = "1" + libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_eq.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_eq.rs index 2922ace8..092300ab 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_eq.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_eq.rs @@ -24,8 +24,8 @@ use crate::builtin::header::field_predicate::FieldPredicate; use crate::builtin::header::field_predicate::Predicate; use filters::failable::filter::FailableFilter; -use failure::Fallible as Result; -use failure::Error; +use anyhow::Result; +use anyhow::Error; use toml::Value; diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_exists.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_exists.rs index 5d157721..1c6d9c44 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_exists.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_exists.rs @@ -22,9 +22,9 @@ use libimagstore::store::Entry; use toml_query::read::TomlValueReadExt; use filters::failable::filter::FailableFilter; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; +use anyhow::Result; +use anyhow::Context; +use anyhow::Error; use crate::builtin::header::field_path::FieldPath; @@ -48,7 +48,7 @@ impl FailableFilter<Entry> for FieldExists { fn filter(&self, e: &Entry) -> Result<bool> { e.get_header() .read(&self.header_field_path[..]) - .context(format_err!("Failed reading header '{}' in '{}'", + .context(anyhow!("Failed reading header '{}' in '{}'", self.header_field_path, e.get_location())) .map_err(Error::from) diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_grep.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_grep.rs index 2badc412..8accc1c7 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_grep.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_grep.rs @@ -27,8 +27,8 @@ use crate::builtin::header::field_predicate::FieldPredicate; use crate::builtin::header::field_predicate::Predicate; use filters::failable::filter::FailableFilter; -use failure::Fallible as Result; -use failure::Error; +use anyhow::Result; +use anyhow::Error; struct EqGrep{ regex: Regex diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_gt.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_gt.rs index 4216cf17..adaf0803 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_gt.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_gt.rs @@ -24,8 +24,8 @@ use crate::builtin::header::field_predicate::FieldPredicate; use crate::builtin::header::field_predicate::Predicate; use filters::failable::filter::FailableFilter; -use failure::Fallible as Result; -use failure::Error; +use anyhow::Result; +use anyhow::Error; use toml::Value; diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_isempty.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_isempty.rs index 0b9c56b3..02a3a352 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_isempty.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_isempty.rs @@ -23,8 +23,8 @@ use toml_query::read::TomlValueReadExt; use crate::builtin::header::field_path::FieldPath; use filters::failable::filter::FailableFilter; -use failure::Fallible as Result; -use failure::Error; +use anyhow::Result; +use anyhow::Error; use toml::Value; diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_istype.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_istype.rs index 41201d6a..db8ba97f 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_istype.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_istype.rs @@ -24,8 +24,8 @@ use crate::builtin::header::field_predicate::FieldPredicate; use crate::builtin::header::field_predicate::Predicate; use filters::failable::filter::FailableFilter; -use failure::Fallible as Result; -use failure::Error; +use anyhow::Result; +use anyhow::Error; use toml::Value; diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_lt.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_lt.rs index 336c0bb5..3ad1b4e1 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_lt.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_lt.rs @@ -24,8 +24,8 @@ use crate::builtin::header::field_predicate::FieldPredicate; use crate::builtin::header::field_predicate::Predicate; use filters::failable::filter::FailableFilter; -use failure::Fallible as Result; -use failure::Error; +use anyhow::Result; +use anyhow::Error; use toml::Value; diff --git a/lib/entry/libimagentryfilter/src/builtin/header/field_predicate.rs b/lib/entry/libimagentryfilter/src/builtin/header/field_predicate.rs index a68696bb..6b7d20b4 100644 --- a/lib/entry/libimagentryfilter/src/builtin/header/field_predicate.rs +++ b/lib/entry/libimagentryfilter/src/builtin/header/field_predicate.rs @@ -25,8 +25,8 @@ use toml::Value; use crate::builtin::header::field_path::FieldPath; use filters::failable::filter::FailableFilter; -use failure::Fallible as Result; -use failure::Error; +use anyhow::Result; +use anyhow::Error; pub trait Predicate { fn evaluate(&self, _: &Value) -> bool; diff --git a/lib/entry/libimagentryfilter/src/lib.rs b/lib/entry/libimagentryfilter/src/lib.rs index a70d3311..2567842c 100644 --- a/lib/entry/libimagentryfilter/src/lib.rs +++ b/lib/entry/libimagentryfilter/src/lib.rs @@ -40,7 +40,7 @@ extern crate regex; extern crate semver; extern crate toml; extern crate toml_query; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate libimagstore; extern crate libimagentrytag; diff --git a/lib/entry/libimagentrygps/Cargo.toml b/lib/entry/libimagentrygps/Cargo.toml index c5122f03..8d2d1f59 100644 --- a/lib/entry/libimagentrygps/Cargo.toml +++ b/lib/entry/libimagentrygps/Cargo.toml @@ -21,11 +21,11 @@ maintenance = { status = "actively-developed" } [dependencies] toml = "0.5.1" -toml-query = "0.9.2" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } serde_derive = "1.0.94" serde = "1.0.94" -failure = "0.1.5" -failure_derive = "0.1.5" +anyhow = "1" + libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } diff --git a/lib/entry/libimagentrygps/src/entry.rs b/lib/entry/libimagentrygps/src/entry.rs index 15b4252e..3999cd6e 100644 --- a/lib/entry/libimagentrygps/src/entry.rs +++ b/lib/entry/libimagentrygps/src/entry.rs @@ -24,9 +24,9 @@ use libimagstore::store::Entry; use toml_query::read::TomlValueReadExt; use toml_query::insert::TomlValueInsertExt; use toml_query::delete::TomlValueDeleteExt; -use failure::ResultExt; -use failure::Fallible as Result; -use failure::Error; +use anyhow::Context; +use anyhow::Result; +use anyhow::Error; pub trait GPSEntry { @@ -60,7 +60,7 @@ impl GPSEntry for Entry { self.get_header_mut() .insert("gps.coordinates", c.into()) .map(|_| ()) - .context(format_err!("Error while inserting header 'gps.coordinates' in '{}'", self.get_location())) + .context(anyhow!("Error while inserting header 'gps.coordinates' in '{}'", self.get_location())) .map_err(Error::from) } @@ -68,7 +68,7 @@ impl GPSEntry for Entry { match self .get_header() .read("gps.coordinates") - .context(format_err!("Error while reading header 'gps.coordinates' in '{}'", self.get_location()))? + .context(anyhow!("Error while reading header 'gps.coordinates' in '{}'", self.get_location()))? { Some(hdr) => Coordinates::from_value(hdr).map(Some), None => Ok(None), @@ -94,7 +94,7 @@ impl GPSEntry for Entry { let hdr = self.get_header_mut(); for pattern in patterns.iter() { let _ = hdr.delete(pattern) - .context(format_err!("Error while deleting header '{}'", pattern)) + .context(anyhow!("Error while deleting header '{}'", pattern)) .context("Error writing header")?; } diff --git a/lib/entry/libimagentrygps/src/lib.rs b/lib/entry/libimagentrygps/src/lib.rs index 4f5dff7c..44323e26 100644 --- a/lib/entry/libimagentrygps/src/lib.rs +++ b/lib/entry/libimagentrygps/src/lib.rs @@ -38,7 +38,7 @@ extern crate toml; extern crate toml_query; #[macro_use] extern crate serde_derive; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; extern crate libimagstore; extern crate libimagerror; diff --git a/lib/entry/libimagentrygps/src/types.rs b/lib/entry/libimagentrygps/src/types.rs index 27deca67..4bda715c 100644 --- a/lib/entry/libimagentrygps/src/types.rs +++ b/lib/entry/libimagentrygps/src/types.rs @@ -23,11 +23,11 @@ use std::fmt::Result as FmtResult; use toml::Value; use toml::map::Map; -use failure::Fallible as Result; -use failure::err_msg; -use failure::Error; +use anyhow::Result; -use libimagerror::errors::ErrorMsg as EM; +use anyhow::Error; + +use libimagerror::errors::Error as EM; pub trait FromValue : Sized { fn from_value(v: &Value) -> Result<Self>; @@ -88,17 +88,17 @@ impl FromValue for GPSValue { Value::Table(ref map) => { Ok(GPSValue::new( map.get("degree") - .ok_or_else(|| err_msg("Degree missing")) + .ok_or_else(|| anyhow!("Degree missing")) .and_then(&int_to_appropriate_width)?, map .get("minutes") - .ok_or_else(|| err_msg("Minutes missing")) + .ok_or_else(|| anyhow!("Minutes missing")) .and_then(&int_to_appropriate_width)?, map .get("seconds") - .ok_or_else(|| err_msg("Seconds missing")) + .ok_or_else(|| anyhow!("Seconds missing")) .and_then(&int_to_appropriate_width)? )) } @@ -154,9 +154,9 @@ impl FromValue for Coordinates { v.as_table() .ok_or_else(|| Error::from(EM::EntryHeaderTypeError)) .and_then(|t| { - let get = |m: &Map<_, _>, what: &'static str, ek| -> Result<GPSValue> { + let get = |m: &Map<_, _>, what: &'static str, ek: &'static str| -> Result<GPSValue> { m.get(what) - .ok_or_else(|| err_msg(ek)) + .ok_or_else(|| anyhow!(ek)) .and_then(GPSValue::from_value) }; diff --git a/lib/entry/libimagentrylink/Cargo.toml b/lib/entry/libimagentrylink/Cargo.toml index 031bdf6b..3e6b0ae6 100644 --- a/lib/entry/libimagentrylink/Cargo.toml +++ b/lib/entry/libimagentrylink/Cargo.toml @@ -27,8 +27,8 @@ url = "2" sha-1 = "0.8.1" hex = "0.4" is-match = "0.1.0" -failure = "0.1.5" -failure_derive = "0.1.5" +anyhow = "1" + serde = "1.0.94" serde_derive = "1.0.94" @@ -37,7 +37,8 @@ libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } libimagutil = { version = "0.10.0", path = "../../../lib/etc/libimagutil" } [dependencies.toml-query] -version = "0.9.2" +git = "https://github.com/matthiasbeyer/toml-query" +branch = "master" default-features = false features = [ "typed" ] diff --git a/lib/entry/libimagentrylink/src/iter.rs b/lib/entry/libimagentrylink/src/iter.rs index 3581a42d..82ec82bd 100644 --- a/lib/entry/libimagentrylink/src/iter.rs +++ b/lib/entry/libimagentrylink/src/iter.rs @@ -20,15 +20,13 @@ use std::vec::IntoIter; -use failure::Error; -use failure::ResultExt; -use failure::Fallible as Result; +use anyhow::Error; +use anyhow::Result; use toml::Value; use itertools::Itertools; use libimagstore::store::Store; use libimagstore::store::FileLockEntry; -use libimagerror::errors::ErrorMsg as EM; use crate::link::Link; @@ -64,7 +62,7 @@ impl<I: Iterator<Item = Link>> IntoValues for I { fn into_values(self) -> Vec<Result<Value>> { self.unique() .sorted() // Cannot sort toml::Value, hence uglyness here - .map(|link| link.to_value().context(EM::ConversionError).map_err(Error::from)) + .map(|link| link.to_value().map_err(Error::from)) .collect() } } diff --git a/lib/entry/libimagentrylink/src/lib.rs b/lib/entry/libimagentrylink/src/lib.rs index 5c324681..93022688 100644 --- a/lib/entry/libimagentrylink/src/lib.rs +++ b/lib/entry/libimagentrylink/src/lib.rs @@ -46,7 +46,7 @@ extern crate sha1; extern crate hex; extern crate serde; #[macro_use] extern crate serde_derive; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; #[macro_use] extern crate is_match; #[cfg(test)] diff --git a/lib/entry/libimagentrylink/src/link.rs b/lib/entry/libimagentrylink/src/link.rs index 997480d5..4f80127e 100644 --- a/lib/entry/libimagentrylink/src/link.rs +++ b/lib/entry/libimagentrylink/src/link.rs @@ -20,12 +20,10 @@ use libimagstore::storeid::StoreId; use libimagstore::storeid::IntoStoreId; use libimagstore::store::Store; -use libimagerror::errors::ErrorMsg as EM; use toml::Value; -use failure::ResultExt; -use failure::Fallible as Result; -use failure::Error; +use anyhow::Result; +use anyhow::Error; #[derive(Eq, PartialOrd, Ord, Debug, Clone)] pub enum Link { @@ -81,7 +79,6 @@ impl Link { } .to_str() .map(Value::String) - .context(EM::ConversionError) .map_err(Error::from) } diff --git a/lib/entry/libimagentrylink/src/linkable.rs b/lib/entry/libimagentrylink/src/linkable.rs index 77cdcd61..7476d82b 100644 --- a/lib/entry/libimagentrylink/src/linkable.rs +++ b/lib/entry/libimagentrylink/src/linkable.rs @@ -26,9 +26,9 @@ use libimagstore::store::Store; use toml_query::read::Partial; use toml_query::read::TomlValueReadExt; use toml_query::insert::TomlValueInsertExt; -use failure::ResultExt; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Context; +use anyhow::Result; + use crate::iter::LinkIter; use crate::link::Link; @@ -222,7 +222,7 @@ impl Linkable for Entry { for id in self.links()?.map(|l| l.get_store_id().clone()) { match store.get(id).context("Failed to get entry")? { Some(mut entry) => self.remove_link(&mut entry)?, - None => return Err(err_msg("Link target does not exist")), + None => return Err(anyhow!("Link target does not exist")), } } @@ -279,9 +279,9 @@ impl Linkable for Entry { /// Check whether an entry is linked to another entry fn is_linked_to(&self, other: &Entry) -> Result<bool> { let left_partial = get_link_partial(self)? - .ok_or_else(|| format_err!("Cannot read links from {}", self.get_location()))?; + .ok_or_else(|| anyhow!("Cannot read links from {}", self.get_location()))?; let right_partial = get_link_partial(&other)? - .ok_or_else(|| format_err!("Cannot read links from {}", other.get_location()))?; + .ok_or_else(|| anyhow!("Cannot read links from {}", other.get_location()))?; let left_id = self.get_location(); let right_id = other.get_location(); @@ -344,7 +344,7 @@ fn alter_linking<F>(left: &mut Entry, right: &mut Entry, f: F) -> Result<()> } fn get_link_partial(entry: &Entry) -> Result<Option<LinkPartial>> { - use failure::Error; + use anyhow::Error; entry.get_header().read_partial::<LinkPartial>().map_err(Error::from) } diff --git a/lib/entry/libimagentrylink/src/storecheck.rs b/lib/entry/libimagentrylink/src/storecheck.rs index 120a8c32..fdcb1b81 100644 --- a/lib/entry/libimagentrylink/src/storecheck.rs +++ b/lib/entry/libimagentrylink/src/storecheck.rs @@ -22,10 +22,10 @@ use std::collections::HashMap; use libimagstore::store::Store; use libimagstore::storeid::StoreId; -use failure::ResultExt; -use failure::Fallible as Result; -use failure::Error; -use failure::err_msg; +use anyhow::Context; +use anyhow::Result; +use anyhow::Error; + use crate::linkable::*; @@ -56,7 +56,7 @@ impl StoreLinkConsistentExt for Store { .fold(Ok(HashMap::new()), |map, element| { map.and_then(|mut map| { debug!("Checking element = {:?}", element); - let entry = element?.ok_or_else(|| err_msg("TODO: Not yet handled"))?; + let entry = element?.ok_or_else(|| anyhow!("TODO: Not yet handled"))?; debug!("Checking entry = {:?}", entry.get_location()); @@ -88,11 +88,11 @@ impl StoreLinkConsistentExt for Store { if !self.exists(id.clone())? { warn!("Does exist in store but not on FS: {:?}", id); - return Err(err_msg("Link target does not exist")) + return Err(anyhow!("Link target does not exist")) } } else { warn!("Does not exist in store: {:?}", id); - return Err(err_msg("Link target does not exist")) + return Err(anyhow!("Link target does not exist")) } } @@ -101,7 +101,7 @@ impl StoreLinkConsistentExt for Store { // Helper function to create a SLCECD::OneDirectionalLink error object let mk_one_directional_link_err = |src: StoreId, target: StoreId| -> Error { - format_err!("Dead link: {} -> {}", + anyhow!("Dead link: {} -> {}", src.local_display_string(), target.local_display_string()) }; diff --git a/lib/entry/libimagentrymarkdown/Cargo.toml b/lib/entry/libimagentrymarkdown/Cargo.toml index 4a23b542..82aa048d 100644 --- a/lib/entry/libimagentrymarkdown/Cargo.toml +++ b/lib/entry/libimagentrymarkdown/Cargo.toml @@ -24,7 +24,7 @@ log = "0.4.6" hoedown = "6.0.0" url = "2" env_logger = "0.7" -failure = "0.1.5" +anyhow = "1" sha-1 = "0.8.1" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } diff --git a/lib/entry/libimagentrymarkdown/src/html.rs b/lib/entry/libimagentrymarkdown/src/html.rs index 8944c58f..66b9f890 100644 --- a/lib/entry/libimagentrymarkdown/src/html.rs +++ b/lib/entry/libimagentrymarkdown/src/html.rs @@ -21,10 +21,10 @@ use hoedown::{Markdown, Html as MdHtml}; use hoedown::renderer::html::Flags as HtmlFlags; use hoedown::renderer::Render; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; -use failure::err_msg; +use anyhow::Result; +use anyhow::Context; +use anyhow::Error; + pub type HTML = String; @@ -35,12 +35,12 @@ pub fn to_html(buffer: &str) -> Result<HTML> { .to_str() .map(String::from) .map_err(Error::from) - .context(err_msg("Markdown rendering error")) + .context(anyhow!("Markdown rendering error")) .map_err(Error::from) } pub mod iter { - use failure::Fallible as Result; + use anyhow::Result; use libimagstore::store::Entry; use super::HTML; use super::to_html; diff --git a/lib/entry/libimagentrymarkdown/src/lib.rs b/lib/entry/libimagentrymarkdown/src/lib.rs index 3b871c2c..6ce26466 100644 --- a/lib/entry/libimagentrymarkdown/src/lib.rs +++ b/lib/entry/libimagentrymarkdown/src/lib.rs @@ -45,7 +45,7 @@ extern crate libimagentrylink; extern crate libimagentryurl; extern crate libimagentryref; extern crate libimagutil; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; #[macro_use] extern crate log; extern crate sha1; diff --git a/lib/entry/libimagentrymarkdown/src/link.rs b/lib/entry/libimagentrymarkdown/src/link.rs index f00f6e9e..f611f719 100644 --- a/lib/entry/libimagentrymarkdown/src/link.rs +++ b/lib/entry/libimagentrymarkdown/src/link.rs @@ -17,10 +17,10 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use failure::ResultExt; -use failure::Fallible as Result; -use failure::Error; -use failure::err_msg; +use anyhow::Context; +use anyhow::Result; +use anyhow::Error; + use hoedown::renderer::Render; use hoedown::Buffer; @@ -39,7 +39,7 @@ impl Link { pub fn into_urllink(self) -> Result<UrlLink> { Url::parse(&self.link[..]) .map(move |link| UrlLink { title: self.title, link, }) - .context(err_msg("Link parsing error")) + .context(anyhow!("Link parsing error")) .map_err(Error::from) } diff --git a/lib/entry/libimagentrymarkdown/src/processor.rs b/lib/entry/libimagentrymarkdown/src/processor.rs index 58a18c62..bc699d4a 100644 --- a/lib/entry/libimagentrymarkdown/src/processor.rs +++ b/lib/entry/libimagentrymarkdown/src/processor.rs @@ -19,9 +19,9 @@ use std::collections::BTreeMap; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; +use anyhow::Result; +use anyhow::Context; +use anyhow::Error; use crate::link::extract_links; use libimagentryurl::linker::UrlLinker; @@ -32,7 +32,6 @@ use libimagentryref::hasher::sha1::Sha1Hasher; use libimagstore::store::Entry; use libimagstore::store::Store; use libimagstore::storeid::StoreId; -use libimagerror::errors::ErrorMsg; use std::path::PathBuf; @@ -148,7 +147,7 @@ impl LinkProcessor { store.retrieve(id)? } else { store.get(id.clone())? - .ok_or_else(|| format_err!("Store get error: {}", id))? + .ok_or_else(|| anyhow!("Store get error: {}", id))? }; entry.add_link(&mut target)?; @@ -180,7 +179,7 @@ impl LinkProcessor { let path = url.host_str().unwrap_or_else(|| url.path()); let path = PathBuf::from(path); let ref_entry_id = { - let digest = Sha1::digest(path.to_str().ok_or(ErrorMsg::UTF8Error)?.as_bytes()); + let digest = Sha1::digest(path.to_str().ok_or_else(|| anyhow!("UTF8 error"))?.as_bytes()); StoreId::new(PathBuf::from(format!("ref/{:x}", digest)))? // TODO: Ugh... }; let mut ref_entry = store.retrieve(ref_entry_id)?; @@ -217,7 +216,7 @@ impl LinkProcessor { LinkQualification::Undecidable(e) => { // error return Err(e) - .context(format_err!("Undecidable link type: {}", link.link.clone())) + .context(anyhow!("Undecidable link type: {}", link.link.clone())) .map_err(Error::from) }, } diff --git a/lib/entry/libimagentryref/Cargo.toml b/lib/entry/libimagentryref/Cargo.toml index 9439486c..75fb8bfc 100644 --- a/lib/entry/libimagentryref/Cargo.toml +++ b/lib/entry/libimagentryref/Cargo.toml @@ -22,7 +22,7 @@ maintenance = { status = "actively-developed" } [dependencies] itertools = "0.8.0" log = "0.4.6" -failure = "0.1.5" +anyhow = "1" sha-1 = "0.8.1" toml = "0.5.1" serde = "1.0.94" @@ -34,7 +34,8 @@ libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" } libimagentryutil = { version = "0.10.0", path = "../../../lib/entry/libimagentryutil" } [dependencies.toml-query] -version = "0.9.2" +git = "https://github.com/matthiasbeyer/toml-query" +branch = "master" default-features = false features = ["typed"] diff --git a/lib/entry/libimagentryref/src/hasher.rs b/lib/entry/libimagentryref/src/hasher.rs index de254d20..06f6f019 100644 --- a/lib/entry/libimagentryref/src/hasher.rs +++ b/lib/entry/libimagentryref/src/hasher.rs @@ -19,7 +19,7 @@ use std::path::Path; -use failure::Fallible as Result; +use anyhow::Result; pub trait Hasher { const NAME: &'static str; @@ -37,7 +37,7 @@ pub mod sha1 { use std::fs::OpenOptions; use std::io::Read; - use failure::Fallible as Result; + use anyhow::Result; use sha1::{Sha1, Digest}; use crate::hasher::Hasher; diff --git a/lib/entry/libimagentryref/src/lib.rs b/lib/entry/libimagentryref/src/lib.rs index b42b8f8f..08f8b922 100644 --- a/lib/entry/libimagentryref/src/lib.rs +++ b/lib/entry/libimagentryref/src/lib.rs @@ -48,7 +48,7 @@ extern crate libimagstore; extern crate libimagrt; extern crate libimagerror; #[macro_use] extern crate libimagentryutil; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; #[cfg(test)] extern crate env_logger; diff --git a/lib/entry/libimagentryref/src/reference.rs b/lib/entry/libimagentryref/src/reference.rs index 0d8970f7..a77403b8 100644 --- a/lib/entry/libimagentryref/src/reference.rs +++ b/lib/entry/libimagentryref/src/reference.rs @@ -24,7 +24,7 @@ use std::ops::Deref; use libimagentryutil::isa::Is; use libimagentryutil::isa::IsKindHeaderPathProvider; -use libimagerror::errors::ErrorMsg as EM; +use libimagerror::errors::Error as EM; use toml::Value; use toml::map::Map; @@ -33,10 +33,10 @@ use toml_query::read::TomlValueReadTypeExt; use toml_query::read::Partial; use toml_query::delete::TomlValueDeleteExt; use toml_query::insert::TomlValueInsertExt; -use failure::Fallible as Result; -use failure::Error; -use failure::err_msg; -use failure::ResultExt; +use anyhow::Result; +use anyhow::Error; + +use anyhow::Context; use crate::hasher::Hasher; @@ -89,9 +89,9 @@ pub mod fassade { use libimagstore::store::Entry; use libimagentryutil::isa::Is; - use failure::Fallible as Result; - use failure::ResultExt; - use failure::Error; + use anyhow::Result; + use anyhow::Context; + use anyhow::Error; use crate::hasher::sha1::Sha1Hasher; use crate::hasher::Hasher; @@ -173,7 +173,7 @@ impl<'a, H: Hasher> Ref for RefWithHasher<'a, H> { self.0 .get_header() .read(&header_path) - .context(format_err!("Failed to read header at '{}'", header_path)) + .context(anyhow!("Failed to read header at '{}'", header_path)) .map_err(Error::from)? .ok_or_else(|| { Error::from(EM::EntryHeaderFieldMissing("ref.hash.<hash>")) @@ -228,19 +228,19 @@ impl<'a, H: Hasher> Ref for RefWithHasher<'a, H> { .get_header() .read("ref") .context("Failed to read header at 'ref'")? - .ok_or_else(|| err_msg("Header missing at 'ref'"))?; + .ok_or_else(|| anyhow!("Header missing at 'ref'"))?; let basepath_name = ref_header .read("basepath") .context("Failed to read header at 'ref.basepath'")? - .ok_or_else(|| err_msg("Header missing at 'ref.basepath'"))? + .ok_or_else(|| anyhow!("Header missing at 'ref.basepath'"))? .as_str() .ok_or_else(|| Error::from(EM::EntryHeaderTypeError2("ref.hash.<hash>", "string")))?; let path = ref_header .read("relpath") .context("Failed to read header at 'ref.relpath'")? - .ok_or_else(|| err_msg("Header missing at 'ref.relpath'"))? + .ok_or_else(|| anyhow!("Header missing at 'ref.relpath'"))? .as_str() .map(PathBuf::from) .ok_or_else(|| Error::from(EM::EntryHeaderTypeError2("ref.hash.<hash>", "string")))?; @@ -250,8 +250,8 @@ impl<'a, H: Hasher> Ref for RefWithHasher<'a, H> { ref_header .read(H::NAME) - .context(format_err!("Failed to read header at 'ref.{}'", H::NAME))? - .ok_or_else(|| format_err!("Header missing at 'ref.{}'", H::NAME)) + .context(anyhow!("Failed to read header at 'ref.{}'", H::NAME))? + .ok_or_else(|| anyhow!("Header missing at 'ref.{}'", H::NAME)) .and_then(|v| { v.as_str().ok_or_else(|| { Error::from(EM::EntryHeaderTypeError2("ref.hash.<hash>", "string")) @@ -329,13 +329,13 @@ impl<'a, H> MutRef for MutRefWithHasher<'a, H> if self.0.get_header().read("ref.is_ref")?.is_some() && !force { debug!("Entry is already a Ref!"); - Err(err_msg("Entry is already a reference")).context("Making ref out of entry")?; + Err(anyhow!("Entry is already a reference")).context("Making ref out of entry")?; } let file_path = get_file_path(config, basepath_name.as_ref(), &path)?; if !file_path.exists() { - let msg = format_err!("File '{:?}' does not exist", file_path); + let msg = anyhow!("File '{:?}' does not exist", file_path); Err(msg).context("Making ref out of entry")?; } @@ -387,7 +387,7 @@ pub(crate) fn make_header_section<P, C, H>(hash: String, hashname: H, relpath: P .to_str() .map(String::from) .ok_or_else(|| { - let msg = format_err!("UTF Error in '{:?}'", relpath.as_ref()); + let msg = anyhow!("UTF Error in '{:?}'", relpath.as_ref()); msg })?; @@ -407,7 +407,7 @@ pub(crate) fn make_header_section<P, C, H>(hash: String, hashname: H, relpath: P fn get_basepath<'a, Coll: AsRef<str>>(basepath_name: Coll, config: &'a Config) -> Result<&'a PathBuf> { config.get(basepath_name.as_ref()) - .ok_or_else(|| format_err!("basepath {} seems not to exist in config", + .ok_or_else(|| anyhow!("basepath {} seems not to exist in config", basepath_name.as_ref())) .map_err(Error::from) } @@ -419,7 +419,7 @@ fn get_file_path<P>(config: &Config, basepath_name: &str, path: P) -> Result<Pat .get(basepath_name) .map(PathBuf::clone) .ok_or_else(|| { - format_err!("Configuration missing for basepath: '{}'", basepath_name) + anyhow!("Configuration missing for basepath: '{}'", basepath_name) }) .context("Making ref out of entry") .map_err(Error::from) @@ -457,7 +457,7 @@ mod test { path.as_ref() .to_str() .map(String::from) - .ok_or_else(|| err_msg("Failed to create test hash")) + .ok_or_else(|| anyhow!("Failed to create test hash")) } } diff --git a/lib/entry/libimagentryref/src/util.rs b/lib/entry/libimagentryref/src/util.rs index 757f894f..10eb5924 100644 --- a/lib/entry/libimagentryref/src/util.rs +++ b/lib/entry/libimagentryref/src/util.rs @@ -17,7 +17,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use failure::Fallible as Result; +use anyhow::Result; use libimagrt::runtime::Runtime; @@ -29,9 +29,9 @@ pub fn get_ref_config(rt: &Runtime, app_name: &'static str) -> Result<RefConfig> let setting_name = "ref.basepathes"; rt.config() - .ok_or_else(|| format_err!("No configuration, cannot find collection name for {}", app_name))? + .ok_or_else(|| anyhow!("No configuration, cannot find collection name for {}", app_name))? .read_deserialized::<RefConfig>(setting_name)? - .ok_or_else(|| format_err!("Setting missing: {}", setting_name)) + .ok_or_else(|| anyhow!("Setting missing: {}", setting_name)) } diff --git a/lib/entry/libimagentrytag/Cargo.toml b/lib/entry/libimagentrytag/Cargo.toml index 9bbadebe..48309238 100644 --- a/lib/entry/libimagentrytag/Cargo.toml +++ b/lib/entry/libimagentrytag/Cargo.toml @@ -25,7 +25,7 @@ regex = "1.1.7" toml = "0.5.1" itertools = "0.8.0" filters = "0.3.0" -failure = "0.1.5" +anyhow = "1" serde = "1.0.94" serde_derive = "1.0.94" @@ -33,7 +33,8 @@ libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } [dependencies.toml-query] -version = "0.9.2" +git = "https://github.com/matthiasbeyer/toml-query" +branch = "master" default-features = false features = [ "typed" ] diff --git a/lib/entry/libimagentrytag/src/lib.rs b/lib/entry/libimagentrytag/src/lib.rs index 9ed51ad9..1133a410 100644 --- a/lib/entry/libimagentrytag/src/lib.rs +++ b/lib/entry/libimagentrytag/src/lib.rs @@ -46,7 +46,7 @@ extern crate toml_query; extern crate serde; #[macro_use] extern crate serde_derive; extern crate filters; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; #[cfg(test)] extern crate env_logger; diff --git a/lib/entry/libimagentrytag/src/tag.rs b/lib/entry/libimagentrytag/src/tag.rs index 86263360..6b6f37e2 100644 --- a/lib/entry/libimagentrytag/src/tag.rs +++ b/lib/entry/libimagentrytag/src/tag.rs @@ -19,7 +19,7 @@ use std::result::Result; -use failure::Error; +use anyhow::Error; pub type Tag = String; pub type TagSlice<'a> = &'a str; @@ -30,7 +30,7 @@ pub fn is_tag(s: String) -> Result<(), String> { } pub fn is_tag_str(s: &str) -> Result<(), Error> { - check_tag_string(s).map_err(|s| format_err!("{}", s)) + check_tag_string(s).map_err(|s| anyhow!("{}", s)) } fn check_tag_string(s: &str) -> Result<(), String> { diff --git a/lib/entry/libimagentrytag/src/tagable.rs b/lib/entry/libimagentrytag/src/tagable.rs index 636e510a..efde0fe5 100644 --- a/lib/entry/libimagentrytag/src/tagable.rs +++ b/lib/entry/libimagentrytag/src/tagable.rs @@ -20,14 +20,14 @@ use itertools::Itertools; use libimagstore::store::Entry; -use libimagerror::errors::ErrorMsg as EM; +use libimagerror::errors::Error as EM; use toml_query::read::TomlValueReadExt; use toml_query::read::Partial; use toml_query::insert::TomlValueInsertExt; -use failure::Error; -use failure::Fallible as Result; +use anyhow::Error; +use anyhow::Result; use crate::tag::{Tag, TagSlice}; use crate::tag::is_tag_str; diff --git a/lib/entry/libimagentryurl/Cargo.toml b/lib/entry/libimagentryurl/Cargo.toml index 2c17d7f8..17b0c3a8 100644 --- a/lib/entry/libimagentryurl/Cargo.toml +++ b/lib/entry/libimagentryurl/Cargo.toml @@ -27,8 +27,8 @@ url = "2" sha-1 = "0.8.1" hex = "0.4" is-match = "0.1.0" -failure = "0.1.5" -failure_derive = "0.1.5" +anyhow = "1" + serde = "1.0.94" serde_derive = "1.0.94" @@ -38,7 +38,8 @@ libimagutil = { version = "0.10.0", path = "../../../lib/etc/libimagutil" } libimagentrylink = { version = "0.10.0", path = "../../../lib/entry/libimagentrylink" } [dependencies.toml-query] -version = "0.9.2" +git = "https://github.com/matthiasbeyer/toml-query" +branch = "master" default-features = false features = [ "typed" ] diff --git a/lib/entry/libimagentryurl/src/iter.rs b/lib/entry/libimagentryurl/src/iter.rs index 1acf4130..e9b2edde 100644 --- a/lib/entry/libimagentryurl/src/iter.rs +++ b/lib/entry/libimagentryurl/src/iter.rs @@ -33,9 +33,8 @@ use libimagentrylink::link::Link; use libimagentrylink::iter::LinkIter; use libimagstore::store::Store; -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; +use anyhow::Result; +use anyhow::Context; use url::Url; /// Helper for building `OnlyUrlIter` and `NoUrlIter` @@ -171,15 +170,12 @@ impl<'a> Iterator for UrlIter<'a> { debug!("Retrieving entry for id: '{:?}'", id); self.1 .retrieve(id.clone()) - .with_context(|e| format!("Retrieving entry for id: '{:?}' failed: {}", id, e)) - .map_err(From::from) + .with_context(|| format!("Retrieving entry for id: '{:?}' failed", id)) .and_then(|f| { debug!("Store::retrieve({:?}) succeeded", id); debug!("getting uri link from file now"); f.get_url() .context("Error happened while getting link URI from FLE") - .with_context(|e| format!("URL -> Err = {:?}", e)) - .map_err(Error::from) }) }); diff --git a/lib/entry/libimagentryurl/src/lib.rs b/lib/entry/libimagentryurl/src/lib.rs index a9ec7f0f..3cb3ee54 100644 --- a/lib/entry/libimagentryurl/src/lib.rs +++ b/lib/entry/libimagentryurl/src/lib.rs @@ -57,7 +57,7 @@ extern crate sha1; extern crate hex; extern crate serde; #[macro_use] extern crate serde_derive; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; #[cfg(test)] extern crate env_logger; diff --git a/lib/entry/libimagentryurl/src/link.rs b/lib/entry/libimagentryurl/src/link.rs index 16786ebc..af4009dc 100644 --- a/lib/entry/libimagentryurl/src/link.rs +++ b/lib/entry/libimagentryurl/src/link.rs @@ -17,17 +17,16 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use failure::Error; -use failure::ResultExt; -use failure::Fallible as Result; -use failure::err_msg; +use anyhow::Error; +use anyhow::Context; +use anyhow::Result; + use url::Url; use toml_query::read::Partial; use toml_query::insert::TomlValueInsertExt; use toml::Value; use libimagstore::store::Entry; -use libimagerror::errors::ErrorMsg as EM; use toml_query::read::TomlValueReadExt; @@ -67,8 +66,7 @@ impl Link for Entry { fn get_url(&self) -> Result<Option<Url>> { let partial = self.get_header() .read_partial::<UrlHeader>() - .context(format_err!("Error reading header 'url.uri' from '{}'", self.get_location())) - .context(EM::EntryHeaderReadError) + .context(anyhow!("Error reading header 'url.uri' from '{}'", self.get_location())) .map_err(Error::from)? .unwrap_or_else(Default::default); @@ -82,8 +80,8 @@ impl Link for Entry { debug!("Found url, parsing: {:?}", url); Url::parse(&url) .map_err(Error::from) - .context(format_err!("Failed to parse URL: '{}'", url)) - .context(err_msg("Invalid URI")) + .context(anyhow!("Failed to parse URL: '{}'", url)) + .context(anyhow!("Invalid URI")) .map_err(Error::from) .map(Some) .context("Failed to get link URI from entry") diff --git a/lib/entry/libimagentryurl/src/linker.rs b/lib/entry/libimagentryurl/src/linker.rs index 3b9d148c..c69e187b 100644 --- a/lib/entry/libimagentryurl/src/linker.rs +++ b/lib/entry/libimagentryurl/src/linker.rs @@ -22,8 +22,8 @@ use libimagstore::store::Store; use libimagstore::store::Entry; use libimagentrylink::linkable::Linkable; -use failure::Fallible as Result; -use failure::ResultExt; +use anyhow::Result; +use anyhow::Context; use url::Url; use sha1::{Sha1, Digest}; use hex; @@ -93,7 +93,7 @@ impl UrlLinker for Entry { links.into_iter().map(|link| { let hash = hex::encode(Sha1::digest(&link.as_str().as_bytes())); let file_id = crate::module_path::new_id(hash.clone()) - .with_context(|e| format!("Failed to build StoreId for this hash '{:?}': {}", hash, e))?; + .with_context(|| format!("Failed to build StoreId for this hash '{:?}'", hash))?; debug!("Link = '{:?}'", link); debug!("Hash = '{:?}'", hash); @@ -105,7 +105,7 @@ impl UrlLinker for Entry { // exist let mut file = store .retrieve(file_id.clone()) - .with_context(|e| format!("Failed to create or retrieve an file for this link '{:?}': {}", link, e))?; + .with_context(|| format!("Failed to create or retrieve an file for this link '{:?}'", link))?; debug!("Generating header content!"); file.set_url(link)?; diff --git a/lib/entry/libimagentryutil/Cargo.toml b/lib/entry/libimagentryutil/Cargo.toml index 1dc11a20..973fe1e9 100644 --- a/lib/entry/libimagentryutil/Cargo.toml +++ b/lib/entry/libimagentryutil/Cargo.toml @@ -21,9 +21,9 @@ maintenance = { status = "actively-developed" } [dependencies] toml = "0.5.1" -toml-query = "0.9.2" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } filters = "0.3.0" -failure = "0.1.5" +anyhow = "1" log = "0.4.6" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } diff --git a/lib/entry/libimagentryutil/src/isa.rs b/lib/entry/libimagentryutil/src/isa.rs index fb493720..a62a213a 100644 --- a/lib/entry/libimagentryutil/src/isa.rs +++ b/lib/entry/libimagentryutil/src/isa.rs @@ -17,9 +17,9 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use failure::Fallible as Result; -use failure::ResultExt; -use failure::Error; +use anyhow::Result; +use anyhow::Context; +use anyhow::Error; use toml::Value; use toml_query::read::TomlValueReadTypeExt; @@ -43,9 +43,9 @@ use toml_query::delete::TomlValueDeleteExt; /// # extern crate libimagstore; /// # #[macro_use] /// # extern crate libimagentryutil; -/// # extern crate failure; +/// # extern crate anyhow; /// -/// use failure::Fallible as Result; +/// use anyhow::Result; /// use libimagentryutil::isa::IsKindHeaderPathProvider; /// use libimagentryutil::isa::Is; /// @@ -81,7 +81,7 @@ impl Is for ::libimagstore::store::Entry { match self .get_header() .read_bool(field) - .context(format_err!("Failed reading header '{}' in '{}'", field, self.get_location())) + .context(anyhow!("Failed reading header '{}' in '{}'", field, self.get_location())) .map_err(Error::from)? { Some(b) => Ok(b), @@ -92,7 +92,7 @@ impl Is for ::libimagstore::store::Entry { fn set_isflag<T: IsKindHeaderPathProvider>(&mut self) -> Result<()> { self.get_header_mut() .insert(T::kindflag_header_location(), Value::Boolean(true)) - .context(format_err!("Failed inserting header '{}' in '{}'", T::kindflag_header_location(), self.get_location())) + .context(anyhow!("Failed inserting header '{}' in '{}'", T::kindflag_header_location(), self.get_location())) .map_err(Error::from) .map(|_| ()) } @@ -101,7 +101,7 @@ impl Is for ::libimagstore::store::Entry { trace!("Trying to remove: {}", T::kindflag_header_location()); self.get_header_mut() .delete(T::kindflag_header_location()) - .context(format_err!("Failed deleting header '{}' in '{}'", T::kindflag_header_location(), self.get_location())) + .context(anyhow!("Failed deleting header '{}' in '{}'", T::kindflag_header_location(), self.get_location())) .map_err(Error::from) .map(|_| ()) } diff --git a/lib/entry/libimagentryutil/src/lib.rs b/lib/entry/libimagentryutil/src/lib.rs index ff6e7edb..b560744b 100644 --- a/lib/entry/libimagentryutil/src/lib.rs +++ b/lib/entry/libimagentryutil/src/lib.rs @@ -40,7 +40,7 @@ extern crate filters; extern crate toml; extern crate toml_query; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; #[macro_use] extern crate log; extern crate libimagstore; diff --git a/lib/entry/libimagentryview/Cargo.toml b/lib/entry/libimagentryview/Cargo.toml index d25d8925..280eb13f 100644 --- a/lib/entry/libimagentryview/Cargo.toml +++ b/lib/entry/libimagentryview/Cargo.toml @@ -22,7 +22,7 @@ maintenance = { status = "actively-developed" } [dependencies] log = "0.4.6" toml = "0.5.1" -failure = "0.1.5" +anyhow = "1" textwrap = "0.11.0" libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" } diff --git a/lib/entry/libimagentryview/src/builtin/editor.rs b/lib/entry/libimagentryview/src/builtin/editor.rs index edc09309..362ea1ab 100644 --- a/lib/entry/libimagentryview/src/builtin/editor.rs +++ b/lib/entry/libimagentryview/src/builtin/editor.rs @@ -24,9 +24,8 @@ use libimagrt::runtime::Runtime; use libimagentryedit::edit::edit_in_tmpfile; use crate::viewer::Viewer; -use crate::error::Result; -use crate::error::Error; -use failure::ResultExt; +use anyhow::Context; +use anyhow::Result; pub struct EditorView<'a>(&'a Runtime<'a>); @@ -41,9 +40,7 @@ impl<'a> Viewer for EditorView<'a> { where W: Write { let mut entry = e.to_str()?; - edit_in_tmpfile(self.0, &mut entry) - .context("Error while viewing") - .map_err(Error::from) + edit_in_tmpfile(self.0, &mut entry).context("Error while viewing") } } diff --git a/lib/entry/libimagentryview/src/builtin/md.rs b/lib/entry/libimagentryview/src/builtin/md.rs index 5ab6632a..065ca28d 100644 --- a/lib/entry/libimagentryview/src/builtin/md.rs +++ b/lib/entry/libimagentryview/src/builtin/md.rs @@ -25,10 +25,10 @@ use libimagrt::runtime::Runtime; use mdcat::{ResourceAccess, TerminalCapabilities, TerminalSize}; use pulldown_cmark::Parser; use syntect::parsing::SyntaxSet; +use anyhow::Result; +use anyhow::Error; use crate::viewer::Viewer; -use crate::error::Result; -use crate::error::Error; pub struct MarkdownViewer<'a> { rt: &'a Runtime<'a>, @@ -64,9 +64,7 @@ impl<'a> Viewer for MarkdownViewer<'a> { base_dir, self.resource_access, syntax_set) - .map_err(|e| e.compat()) - .map_err(::failure::Error::from) - .map_err(Error::from) + .map_err(|e| Error::from(e.compat())) } } diff --git a/lib/entry/libimagentryview/src/builtin/plain.rs b/lib/entry/libimagentryview/src/builtin/plain.rs index a8e2da46..2b2a6f5a 100644 --- a/lib/entry/libimagentryview/src/builtin/plain.rs +++ b/lib/entry/libimagentryview/src/builtin/plain.rs @@ -22,7 +22,7 @@ use std::io::Write; use libimagstore::store::Entry; use crate::viewer::Viewer; -use crate::error::Result; +use anyhow::Result; pub struct PlainViewer { show_header: bool diff --git a/lib/entry/libimagentryview/src/builtin/stdout.rs b/lib/entry/libimagentryview/src/builtin/stdout.rs index e5a9734b..1051c778 100644 --- a/lib/entry/libimagentryview/src/builtin/stdout.rs +++ b/lib/entry/libimagentryview/src/builtin/stdout.rs @@ -24,7 +24,7 @@ use libimagstore::store::Entry; use toml::ser::to_string; use crate::viewer::Viewer; -use crate::error::Result; +use anyhow::Result; pub struct StdoutViewer { view_header: bool, diff --git a/lib/entry/libimagentryview/src/error.rs b/lib/entry/libimagentryview/src/error.rs index afa64ab4..5f45d7a0 100644 --- a/lib/entry/libimagentryview/src/error.rs +++ b/lib/entry/libimagentryview/src/error.rs @@ -18,14 +18,11 @@ // use std::fmt::Display; -use std::fmt::Debug; - -use failure::Fail; #[derive(Debug)] pub enum Error { Io(::std::io::Error), - Other(::failure::Error), + Other(::anyhow::Error), } impl Display for Error { @@ -37,30 +34,24 @@ impl Display for Error { } } -impl Fail for Error { - /* empty */ -} - impl From<::std::io::Error> for Error { fn from(ioe: ::std::io::Error) -> Self { Error::Io(ioe) } } -impl From<::failure::Error> for Error { - fn from(fe: ::failure::Error) -> Self { +impl From<::anyhow::Error> for Error { + fn from(fe: ::anyhow::Error) -> Self { Error::Other(fe) } } -impl<D> From<::failure::Context<D>> for Error - where D: Debug + Display + Send + Sync -{ - fn from(ctx: ::failure::Context<D>) -> Self { - Error::Other(ctx.into()) +impl Into<::anyhow::Error> for Error { + fn into(self) -> ::anyhow::Error { + match self { + Error::Io(e) => ::anyhow::Error::from(e), + Error::Other(e) => e, + } } } -/// Convenient helper type -pub type Result<T> = ::std::result::Result<T, Error>; - diff --git a/lib/entry/libimagentryview/src/lib.rs b/lib/entry/libimagentryview/src/lib.rs index 485aaec8..f0d60bd9 100644 --- a/lib/entry/libimagentryview/src/lib.rs +++ b/lib/entry/libimagentryview/src/lib.rs @@ -40,7 +40,7 @@ #[macro_use] extern crate log; extern crate toml; extern crate textwrap; -extern crate failure; +extern crate anyhow; #[cfg(feature = "markdownviewer")] extern crate mdcat; diff --git a/lib/entry/libimagentryview/src/viewer.rs b/lib/entry/libimagentryview/src/viewer.rs index 1fa2271c..f4a9b3e0 100644 --- a/lib/entry/libimagentryview/src/viewer.rs +++ b/lib/entry/libimagentryview/src/viewer.rs @@ -23,7 +23,7 @@ use std::ops::Deref; use libimagstore::store::Entry; use libimagstore::store::FileLockEntry; -use crate::error::Result; +use anyhow::Result; pub trait Viewer { @@ -125,20 +125,22 @@ impl<'a, I, V, W, F, T> Iterator for ViewIter<'a, I, V, W, F, T> F: Fn(&T) -> Option<&FileLockEntry>, T: Sized, { - type Item = failure::Fallible<T>; + type Item = Result<T>; fn next(&mut self) -> Option<Self::Item> { if let Some(next) = self.inner.next() { if let Some(entry) = (self.func)(&next) { let r = self.viewer.view_entry(&entry, self.sink); trace!("Viewing resulted in {:?}", r); - match r { - Ok(_) => { /* nothing */ }, - Err(crate::error::Error::Io(ref e)) if e.kind() == std::io::ErrorKind::BrokenPipe => { - trace!("Stopping iteration, because of broken pipe error!"); - return None - }, - Err(e) => return Some(Err(failure::Error::from(e))) + if let Err(e) = r { + if let Some(ioerr) = e.downcast_ref::<::std::io::Error>() { + if ioerr.kind() == ::std::io::ErrorKind::BrokenPipe { + trace!("Stopping iteration, because of broken pipe error!"); + return None + } + } + + return Some(Err(e)) } } diff --git a/lib/etc/libimaginteraction/Cargo.toml b/lib/etc/libimaginteraction/Cargo.toml index 01c6e0c7..f83b06a3 100644 --- a/lib/etc/libimaginteraction/Cargo.toml +++ b/lib/etc/libimaginteraction/Cargo.toml @@ -30,8 +30,8 @@ handlebars = "2" serde_json = "1.0.39" serde_derive = "1" serde = "1" -failure = "0.1.5" -failure_derive = "0.1.5" +anyhow = "1" + libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } diff --git a/lib/etc/libimaginteraction/src/ask.rs b/lib/etc/libimaginteraction/src/ask.rs index 99affeb6..0edff421 100644 --- a/lib/etc/libimaginteraction/src/ask.rs +++ b/lib/etc/libimaginteraction/src/ask.rs @@ -26,9 +26,9 @@ use std::io::Write; use regex::Regex; use ansi_term::Colour::*; -use failure::Error; -use failure::ResultExt; -use failure::Fallible as Result; +use anyhow::Error; +use anyhow::Context; +use anyhow::Result; /// Ask the user for a Yes/No answer. Optionally provide a default value. If none is provided, this /// keeps loop{}ing diff --git a/lib/etc/libimaginteraction/src/lib.rs b/lib/etc/libimaginteraction/src/lib.rs index 980ab92c..e3bdaec7 100644 --- a/lib/etc/libimaginteraction/src/lib.rs +++ b/lib/etc/libimaginteraction/src/lib.rs @@ -47,7 +47,7 @@ extern crate handlebars; extern crate serde; #[macro_use] extern crate serde_derive; extern crate serde_json; -extern crate failure; +#[macro_use] extern crate anyhow; extern crate libimagstore; extern crate libimagerror; diff --git a/lib/etc/libimaginteraction/src/ui.rs b/lib/etc/libimaginteraction/src/ui.rs index 4460ac79..6dd9528e 100644 --- a/lib/etc/libimaginteraction/src/ui.rs +++ b/lib/etc/libimaginteraction/src/ui.rs @@ -23,8 +23,8 @@ use clap::{Arg, ArgMatches}; use libimagstore::storeid::StoreId; -use failure::err_msg; -use failure::Fallible as Result; + +use anyhow::Result; pub fn id_argument<'a, 'b>() -> Arg<'a, 'b> { Arg::with_name(id_argument_name()) @@ -50,7 +50,7 @@ pub fn id_argument_long() -> &'static str { pub fn get_id(matches: &ArgMatches) -> Result<Vec<StoreId>> { matches .values_of(id_argument_name()) - .ok_or_else(|| err_msg("CLI error")) + .ok_or_else(|| anyhow!("CLI error")) .and_then(|vals| { vals .fold(Ok(vec![]), |acc, elem| { diff --git a/lib/etc/libimagutil/src/testing.rs b/lib/etc/libimagutil/src/testing.rs index 81e83678..2a11a7d6 100644 --- a/lib/etc/libimagutil/src/testing.rs +++ b/lib/etc/libimagutil/src/testing.rs @@ -53,7 +53,7 @@ macro_rules! make_mock_app { use libimagrt::runtime::Runtime; use libimagrt::configuration::InternalConfiguration; use toml::Value; - use failure::Error; + use anyhow::Error; #[derive(Clone)] struct MockLinkApp<'a> { diff --git a/tests/version-sync/Cargo.toml b/tests/version-sync/Cargo.toml index f6987af5..2be3e147 100644 --- a/tests/version-sync/Cargo.toml +++ b/tests/version-sync/Cargo.toml @@ -15,5 +15,5 @@ env_logger = "0.7" log = "0.4.6" version-sync = "0.8" walkdir = "2" -toml-query = "0.9" +toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" } toml = "0.5" |