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 /lib/core/libimagrt/src/logger.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 'lib/core/libimagrt/src/logger.rs')
-rw-r--r-- | lib/core/libimagrt/src/logger.rs | 49 |
1 files changed, 17 insertions, 32 deletions
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) } |