diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-03-07 16:04:33 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-03-08 11:43:24 +0100 |
commit | 8527d447ae2047e0d5d54cc70599a895b62a3ee0 (patch) | |
tree | 023de5d446d28c6a232308f8604e17a129ee49c7 /bin | |
parent | 00aa4df88edae1d5eeb3fb365af05f95bd0de3b4 (diff) |
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 <mail@beyermatthias.de>
Diffstat (limited to 'bin')
109 files changed, 562 insertions, 565 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::<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..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; |