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/core/imag/src/main.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/core/imag/src/main.rs')
-rw-r--r-- | bin/core/imag/src/main.rs | 28 |
1 files changed, 14 insertions, 14 deletions
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")), } } |