From 8527d447ae2047e0d5d54cc70599a895b62a3ee0 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 7 Mar 2020 16:04:33 +0100 Subject: Replace failure with anyhow in complete codebase This patch was scripted with sed -i 's/use failure::Error/use anyhow::Error/' $(rg "use failure::Error" -l) sed -i 's/use failure::Fallible as /use anyhow::/' $(rg "use failure::Fallible" -l) sed -i 's/failure/anyhow/' $(rg "failure *=" -l) sed -i 's/format_err!/anyhow!/' $(rg "format_err!" -l) sed -i 's/use failure::ResultExt/use anyhow::Context/' $(rg "use failure::ResultExt" -l) sed -i 's/err_msg/anyhow!/' $(rg "use failure::err_msg" -l) sed -i 's/^anyhow\ *=.*$/anyhow = "1"/' $(rg "anyhow * =" -l) sed -i 's/^anyhow_derive.*//' $(rg "anyhow_derive" -l) sed -i 's/extern crate failure/extern crate anyhow/' $(rg "extern crate failure" -l) sed -i 's/.*extern crate anyhow_derive.*//' $(rg "anyhow_derive" -l) Some manual changes were added as well, so this patch was not completely scripted, but mostly. Signed-off-by: Matthias Beyer --- bin/core/imag-annotate/Cargo.toml | 2 +- bin/core/imag-annotate/src/lib.rs | 30 ++--- bin/core/imag-annotate/src/ui.rs | 4 +- bin/core/imag-category/Cargo.toml | 2 +- bin/core/imag-category/src/lib.rs | 24 ++-- bin/core/imag-category/src/ui.rs | 6 +- bin/core/imag-create/Cargo.toml | 2 +- bin/core/imag-create/src/lib.rs | 8 +- bin/core/imag-create/src/ui.rs | 2 +- bin/core/imag-diagnostics/Cargo.toml | 2 +- bin/core/imag-diagnostics/src/lib.rs | 12 +- bin/core/imag-edit/Cargo.toml | 2 +- bin/core/imag-edit/src/lib.rs | 10 +- bin/core/imag-edit/src/ui.rs | 2 +- bin/core/imag-git/Cargo.toml | 2 +- bin/core/imag-git/src/lib.rs | 24 ++-- bin/core/imag-gps/Cargo.toml | 2 +- bin/core/imag-gps/src/lib.rs | 30 ++--- bin/core/imag-gps/src/ui.rs | 4 +- bin/core/imag-grep/Cargo.toml | 2 +- bin/core/imag-grep/src/lib.rs | 10 +- bin/core/imag-header/Cargo.toml | 2 +- bin/core/imag-header/src/lib.rs | 16 +-- bin/core/imag-header/src/ui.rs | 2 +- bin/core/imag-id-in-collection/Cargo.toml | 2 +- bin/core/imag-id-in-collection/src/lib.rs | 8 +- bin/core/imag-id-in-collection/src/ui.rs | 2 +- bin/core/imag-ids/Cargo.toml | 2 +- bin/core/imag-ids/src/lib.rs | 8 +- bin/core/imag-ids/src/ui.rs | 4 +- bin/core/imag-init/Cargo.toml | 2 +- bin/core/imag-init/src/bin.rs | 4 +- bin/core/imag-init/src/lib.rs | 24 ++-- bin/core/imag-link/Cargo.toml | 2 +- bin/core/imag-link/src/lib.rs | 40 +++--- bin/core/imag-link/src/ui.rs | 2 +- bin/core/imag-markdown/Cargo.toml | 2 +- bin/core/imag-markdown/src/lib.rs | 12 +- bin/core/imag-markdown/src/ui.rs | 2 +- bin/core/imag-mv/Cargo.toml | 2 +- bin/core/imag-mv/src/lib.rs | 14 +-- bin/core/imag-ref/Cargo.toml | 2 +- bin/core/imag-ref/src/lib.rs | 26 ++-- bin/core/imag-ref/src/ui.rs | 6 +- bin/core/imag-store/Cargo.toml | 2 +- bin/core/imag-store/src/create.rs | 6 +- bin/core/imag-store/src/delete.rs | 2 +- bin/core/imag-store/src/get.rs | 6 +- bin/core/imag-store/src/lib.rs | 10 +- bin/core/imag-store/src/retrieve.rs | 2 +- bin/core/imag-store/src/update.rs | 2 +- bin/core/imag-store/src/verify.rs | 8 +- bin/core/imag-tag/Cargo.toml | 2 +- bin/core/imag-tag/src/lib.rs | 20 +-- bin/core/imag-tag/src/ui.rs | 2 +- bin/core/imag-view/Cargo.toml | 2 +- bin/core/imag-view/src/lib.rs | 24 ++-- bin/core/imag-view/src/ui.rs | 2 +- bin/core/imag/Cargo.toml | 2 +- bin/core/imag/src/main.rs | 28 ++--- bin/domain/imag-bookmark/Cargo.toml | 2 +- bin/domain/imag-bookmark/src/lib.rs | 38 +++--- bin/domain/imag-bookmark/src/ui.rs | 6 +- bin/domain/imag-calendar/Cargo.toml | 1 + bin/domain/imag-calendar/src/filters.rs | 8 +- bin/domain/imag-calendar/src/lib.rs | 35 +++--- bin/domain/imag-calendar/src/util.rs | 26 ++-- bin/domain/imag-contact/Cargo.toml | 2 +- bin/domain/imag-contact/src/create.rs | 48 ++++---- bin/domain/imag-contact/src/edit.rs | 12 +- bin/domain/imag-contact/src/lib.rs | 34 +++--- bin/domain/imag-contact/src/ui.rs | 2 +- bin/domain/imag-contact/src/util.rs | 8 +- bin/domain/imag-diary/Cargo.toml | 2 +- bin/domain/imag-diary/src/create.rs | 26 ++-- bin/domain/imag-diary/src/delete.rs | 10 +- bin/domain/imag-diary/src/lib.rs | 12 +- bin/domain/imag-diary/src/list.rs | 8 +- bin/domain/imag-diary/src/util.rs | 11 +- bin/domain/imag-diary/src/view.rs | 10 +- bin/domain/imag-habit/Cargo.toml | 2 +- bin/domain/imag-habit/src/lib.rs | 39 +++--- bin/domain/imag-log/Cargo.toml | 2 +- bin/domain/imag-log/src/lib.rs | 24 ++-- bin/domain/imag-mail/Cargo.toml | 2 +- bin/domain/imag-mail/src/lib.rs | 26 ++-- bin/domain/imag-mail/src/ui.rs | 2 +- bin/domain/imag-mail/src/util.rs | 10 +- bin/domain/imag-notes/Cargo.toml | 2 +- bin/domain/imag-notes/src/lib.rs | 16 +-- bin/domain/imag-timetrack/Cargo.toml | 3 +- bin/domain/imag-timetrack/src/cont.rs | 4 +- bin/domain/imag-timetrack/src/day.rs | 4 +- bin/domain/imag-timetrack/src/lib.rs | 9 +- bin/domain/imag-timetrack/src/list.rs | 13 +- bin/domain/imag-timetrack/src/month.rs | 4 +- bin/domain/imag-timetrack/src/shell.rs | 12 +- bin/domain/imag-timetrack/src/start.rs | 4 +- bin/domain/imag-timetrack/src/stop.rs | 4 +- bin/domain/imag-timetrack/src/track.rs | 10 +- bin/domain/imag-timetrack/src/week.rs | 4 +- bin/domain/imag-timetrack/src/year.rs | 4 +- bin/domain/imag-todo/Cargo.toml | 2 +- bin/domain/imag-todo/src/import.rs | 23 ++-- bin/domain/imag-todo/src/lib.rs | 64 +++++----- bin/domain/imag-todo/src/ui.rs | 2 +- bin/domain/imag-todo/src/util.rs | 15 ++- bin/domain/imag-wiki/Cargo.toml | 2 +- bin/domain/imag-wiki/src/lib.rs | 30 ++--- lib/core/libimagerror/Cargo.toml | 4 +- lib/core/libimagerror/src/lib.rs | 4 +- lib/core/libimagerror/src/trace.rs | 2 +- lib/core/libimagrt/Cargo.toml | 4 +- lib/core/libimagrt/src/application.rs | 8 +- lib/core/libimagrt/src/configuration.rs | 19 ++- lib/core/libimagrt/src/iter.rs | 4 +- lib/core/libimagrt/src/lib.rs | 2 +- lib/core/libimagrt/src/logger.rs | 49 +++----- lib/core/libimagrt/src/runtime.rs | 38 +++--- lib/core/libimagstore/Cargo.toml | 4 +- lib/core/libimagstore/src/configuration.rs | 13 +- lib/core/libimagstore/src/file_abstraction/fs.rs | 45 +++---- .../libimagstore/src/file_abstraction/inmemory.rs | 10 +- lib/core/libimagstore/src/file_abstraction/iter.rs | 2 +- lib/core/libimagstore/src/file_abstraction/mod.rs | 2 +- lib/core/libimagstore/src/iter.rs | 4 +- lib/core/libimagstore/src/lib.rs | 2 +- lib/core/libimagstore/src/store.rs | 134 ++++++++++----------- lib/core/libimagstore/src/storeid.rs | 18 +-- lib/core/libimagstore/src/util.rs | 13 +- lib/domain/libimagbookmark/Cargo.toml | 2 +- lib/domain/libimagbookmark/src/bookmark.rs | 2 +- lib/domain/libimagbookmark/src/lib.rs | 2 +- lib/domain/libimagbookmark/src/store.rs | 6 +- lib/domain/libimagcalendar/Cargo.toml | 3 +- lib/domain/libimagcalendar/src/event.rs | 2 +- lib/domain/libimagcalendar/src/lib.rs | 3 +- lib/domain/libimagcalendar/src/store.rs | 8 +- lib/domain/libimagcontact/Cargo.toml | 3 +- lib/domain/libimagcontact/src/contact.rs | 6 +- lib/domain/libimagcontact/src/iter.rs | 8 +- lib/domain/libimagcontact/src/lib.rs | 3 +- lib/domain/libimagcontact/src/store.rs | 14 ++- lib/domain/libimagcontact/src/util.rs | 2 +- lib/domain/libimagdiary/Cargo.toml | 2 +- lib/domain/libimagdiary/src/diary.rs | 6 +- lib/domain/libimagdiary/src/diaryid.rs | 20 +-- lib/domain/libimagdiary/src/entry.rs | 2 +- lib/domain/libimagdiary/src/iter.rs | 6 +- lib/domain/libimagdiary/src/lib.rs | 2 +- lib/domain/libimagdiary/src/viewer.rs | 9 +- lib/domain/libimaghabit/Cargo.toml | 2 +- lib/domain/libimaghabit/src/habit.rs | 26 ++-- lib/domain/libimaghabit/src/instance.rs | 6 +- lib/domain/libimaghabit/src/iter.rs | 6 +- lib/domain/libimaghabit/src/lib.rs | 2 +- lib/domain/libimaghabit/src/store.rs | 2 +- lib/domain/libimaghabit/src/util.rs | 10 +- lib/domain/libimaglog/Cargo.toml | 2 +- lib/domain/libimaglog/src/lib.rs | 2 +- lib/domain/libimaglog/src/log.rs | 6 +- lib/domain/libimagmail/Cargo.toml | 2 +- lib/domain/libimagmail/src/fetch.rs | 2 +- lib/domain/libimagmail/src/hasher.rs | 2 +- lib/domain/libimagmail/src/iter.rs | 10 +- lib/domain/libimagmail/src/lib.rs | 2 +- lib/domain/libimagmail/src/mail.rs | 22 ++-- lib/domain/libimagmail/src/mailflags.rs | 6 +- lib/domain/libimagmail/src/send.rs | 4 +- lib/domain/libimagmail/src/store.rs | 8 +- lib/domain/libimagmail/src/util.rs | 12 +- lib/domain/libimagnotes/Cargo.toml | 2 +- lib/domain/libimagnotes/src/iter.rs | 6 +- lib/domain/libimagnotes/src/lib.rs | 2 +- lib/domain/libimagnotes/src/note.rs | 10 +- lib/domain/libimagnotes/src/notestore.rs | 2 +- lib/domain/libimagtimetrack/Cargo.toml | 2 +- lib/domain/libimagtimetrack/src/iter/create.rs | 6 +- lib/domain/libimagtimetrack/src/iter/get.rs | 2 +- lib/domain/libimagtimetrack/src/iter/setendtime.rs | 2 +- lib/domain/libimagtimetrack/src/iter/storeid.rs | 4 +- lib/domain/libimagtimetrack/src/iter/tag.rs | 6 +- lib/domain/libimagtimetrack/src/lib.rs | 2 +- lib/domain/libimagtimetrack/src/store.rs | 8 +- lib/domain/libimagtimetrack/src/tag.rs | 2 +- lib/domain/libimagtimetrack/src/timetracking.rs | 24 ++-- lib/domain/libimagtodo/Cargo.toml | 2 +- lib/domain/libimagtodo/src/builder.rs | 10 +- lib/domain/libimagtodo/src/entry.rs | 8 +- lib/domain/libimagtodo/src/iter.rs | 4 +- lib/domain/libimagtodo/src/lib.rs | 2 +- lib/domain/libimagtodo/src/status.rs | 6 +- lib/domain/libimagtodo/src/store.rs | 2 +- lib/domain/libimagwiki/Cargo.toml | 2 +- lib/domain/libimagwiki/src/entry.rs | 8 +- lib/domain/libimagwiki/src/lib.rs | 2 +- lib/domain/libimagwiki/src/store.rs | 2 +- lib/domain/libimagwiki/src/wiki.rs | 14 +-- lib/entry/libimagentryannotation/Cargo.toml | 4 +- .../libimagentryannotation/src/annotateable.rs | 12 +- .../src/annotation_fetcher.rs | 2 +- lib/entry/libimagentryannotation/src/lib.rs | 2 +- lib/entry/libimagentrycategory/Cargo.toml | 2 +- lib/entry/libimagentrycategory/src/category.rs | 12 +- lib/entry/libimagentrycategory/src/entry.rs | 22 ++-- lib/entry/libimagentrycategory/src/iter.rs | 16 +-- lib/entry/libimagentrycategory/src/lib.rs | 2 +- lib/entry/libimagentrycategory/src/store.rs | 23 ++-- lib/entry/libimagentrydatetime/Cargo.toml | 2 +- .../libimagentrydatetime/src/datepath/compiler.rs | 2 +- .../src/datepath/to_store_id.rs | 2 +- lib/entry/libimagentrydatetime/src/datetime.rs | 18 +-- lib/entry/libimagentrydatetime/src/lib.rs | 2 +- lib/entry/libimagentrydatetime/src/range.rs | 6 +- lib/entry/libimagentryedit/Cargo.toml | 2 +- lib/entry/libimagentryedit/src/edit.rs | 15 ++- lib/entry/libimagentryedit/src/lib.rs | 2 +- lib/entry/libimagentryfilter/Cargo.toml | 4 +- .../src/builtin/header/field_eq.rs | 4 +- .../src/builtin/header/field_exists.rs | 8 +- .../src/builtin/header/field_grep.rs | 4 +- .../src/builtin/header/field_gt.rs | 4 +- .../src/builtin/header/field_isempty.rs | 4 +- .../src/builtin/header/field_istype.rs | 4 +- .../src/builtin/header/field_lt.rs | 4 +- .../src/builtin/header/field_predicate.rs | 4 +- lib/entry/libimagentryfilter/src/lib.rs | 2 +- lib/entry/libimagentrygps/Cargo.toml | 4 +- lib/entry/libimagentrygps/src/entry.rs | 12 +- lib/entry/libimagentrygps/src/lib.rs | 2 +- lib/entry/libimagentrygps/src/types.rs | 18 +-- lib/entry/libimagentrylink/Cargo.toml | 4 +- lib/entry/libimagentrylink/src/iter.rs | 8 +- lib/entry/libimagentrylink/src/lib.rs | 2 +- lib/entry/libimagentrylink/src/link.rs | 7 +- lib/entry/libimagentrylink/src/linkable.rs | 14 +-- lib/entry/libimagentrylink/src/storecheck.rs | 16 +-- lib/entry/libimagentrymarkdown/Cargo.toml | 2 +- lib/entry/libimagentrymarkdown/src/html.rs | 12 +- lib/entry/libimagentrymarkdown/src/lib.rs | 2 +- lib/entry/libimagentrymarkdown/src/link.rs | 10 +- lib/entry/libimagentrymarkdown/src/processor.rs | 13 +- lib/entry/libimagentryref/Cargo.toml | 2 +- lib/entry/libimagentryref/src/hasher.rs | 4 +- lib/entry/libimagentryref/src/lib.rs | 2 +- lib/entry/libimagentryref/src/reference.rs | 40 +++--- lib/entry/libimagentryref/src/util.rs | 6 +- lib/entry/libimagentrytag/Cargo.toml | 2 +- lib/entry/libimagentrytag/src/lib.rs | 2 +- lib/entry/libimagentrytag/src/tag.rs | 4 +- lib/entry/libimagentrytag/src/tagable.rs | 6 +- lib/entry/libimagentryurl/Cargo.toml | 4 +- lib/entry/libimagentryurl/src/iter.rs | 10 +- lib/entry/libimagentryurl/src/lib.rs | 2 +- lib/entry/libimagentryurl/src/link.rs | 16 ++- lib/entry/libimagentryurl/src/linker.rs | 8 +- lib/entry/libimagentryutil/Cargo.toml | 2 +- lib/entry/libimagentryutil/src/isa.rs | 16 +-- lib/entry/libimagentryutil/src/lib.rs | 2 +- lib/entry/libimagentryview/Cargo.toml | 2 +- lib/entry/libimagentryview/src/builtin/editor.rs | 9 +- lib/entry/libimagentryview/src/builtin/md.rs | 8 +- lib/entry/libimagentryview/src/builtin/plain.rs | 2 +- lib/entry/libimagentryview/src/builtin/stdout.rs | 2 +- lib/entry/libimagentryview/src/error.rs | 24 +--- lib/entry/libimagentryview/src/lib.rs | 2 +- lib/entry/libimagentryview/src/viewer.rs | 20 +-- lib/etc/libimaginteraction/Cargo.toml | 4 +- lib/etc/libimaginteraction/src/ask.rs | 6 +- lib/etc/libimaginteraction/src/lib.rs | 2 +- lib/etc/libimaginteraction/src/ui.rs | 6 +- lib/etc/libimagutil/src/testing.rs | 2 +- 272 files changed, 1177 insertions(+), 1251 deletions(-) diff --git a/bin/core/imag-annotate/Cargo.toml b/bin/core/imag-annotate/Cargo.toml index 5c5b89da..34e0ef4f 100644 --- a/bin/core/imag-annotate/Cargo.toml +++ b/bin/core/imag-annotate/Cargo.toml @@ -24,7 +24,7 @@ log = "0.4.6" url = "2" toml = "0.5.1" toml-query = "0.9.2" -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-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::() .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::() .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::() .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..6f75f487 100644 --- a/bin/core/imag-category/Cargo.toml +++ b/bin/core/imag-category/Cargo.toml @@ -23,7 +23,7 @@ maintenance = { status = "actively-developed" } log = "0.4.6" toml = "0.5.1" toml-query = "0.9.2" -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-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::()? - .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::()? - .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>> { fn no_ids_error() -> Result>> { - 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>> { @@ -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::()? - .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..4637006e 100644 --- a/bin/core/imag-diagnostics/Cargo.toml +++ b/bin/core/imag-diagnostics/Cargo.toml @@ -18,7 +18,7 @@ log = "0.4.6" toml = "0.5.1" toml-query = "0.9.2" 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> { - 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..5e7a0df7 100644 --- a/bin/core/imag-edit/Cargo.toml +++ b/bin/core/imag-edit/Cargo.toml @@ -24,7 +24,7 @@ log = "0.4.6" version = "3.0.0" toml = "0.5.1" toml-query = "0.9.2" -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-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::()? - .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..af18fdfa 100644 --- a/bin/core/imag-git/Cargo.toml +++ b/bin/core/imag-git/Cargo.toml @@ -23,7 +23,7 @@ maintenance = { status = "actively-developed" } log = "0.4.6" toml = "0.5.1" toml-query = "0.9.2" -failure = "0.1.5" +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..8b09b751 100644 --- a/bin/core/imag-gps/Cargo.toml +++ b/bin/core/imag-gps/Cargo.toml @@ -24,7 +24,7 @@ log = "0.4.6" url = "2" toml = "0.5.1" toml-query = "0.9.2" -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-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> { rt .ids::()? - .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::>>()?; - 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..6f293f0c 100644 --- a/bin/core/imag-header/Cargo.toml +++ b/bin/core/imag-header/Cargo.toml @@ -25,7 +25,7 @@ version = "3.0.0" toml = "0.5.1" toml-query = "0.9.2" 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::()? - .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..19da86fa 100644 --- a/bin/core/imag-id-in-collection/Cargo.toml +++ b/bin/core/imag-id-in-collection/Cargo.toml @@ -24,7 +24,7 @@ filters = "0.3.0" log = "0.4.6" toml = "0.5.1" toml-query = "0.9.2" -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-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::()? - .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..8095decd 100644 --- a/bin/core/imag-ids/Cargo.toml +++ b/bin/core/imag-ids/Cargo.toml @@ -23,7 +23,7 @@ maintenance = { status = "actively-developed" } log = "0.4.6" toml = "0.5.1" toml-query = "0.9.2" -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-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::()? - .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>> { - 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..c7e53105 100644 --- a/bin/core/imag-link/Cargo.toml +++ b/bin/core/imag-link/Cargo.toml @@ -25,7 +25,7 @@ url = "2" toml = "0.5.1" toml-query = "0.9.2" 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 { 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::()? - .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::()? - .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::()? - .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