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/domain/imag-bookmark/src/lib.rs | |
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/domain/imag-bookmark/src/lib.rs')
-rw-r--r-- | bin/domain/imag-bookmark/src/lib.rs | 38 |
1 files changed, 19 insertions, 19 deletions
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()) |