diff options
Diffstat (limited to 'lib/core/libimagrt/src')
-rw-r--r-- | lib/core/libimagrt/src/application.rs | 8 | ||||
-rw-r--r-- | lib/core/libimagrt/src/configuration.rs | 19 | ||||
-rw-r--r-- | lib/core/libimagrt/src/iter.rs | 4 | ||||
-rw-r--r-- | lib/core/libimagrt/src/lib.rs | 2 | ||||
-rw-r--r-- | lib/core/libimagrt/src/logger.rs | 49 | ||||
-rw-r--r-- | lib/core/libimagrt/src/runtime.rs | 38 |
6 files changed, 52 insertions, 68 deletions
diff --git a/lib/core/libimagrt/src/application.rs b/lib/core/libimagrt/src/application.rs index 3ff20d1f..cb5b9b26 100644 --- a/lib/core/libimagrt/src/application.rs +++ b/lib/core/libimagrt/src/application.rs @@ -19,7 +19,7 @@ use runtime::Runtime; use clap::App; -use failure::Fallible as Result; +use anyhow::Result; pub trait ImagApplication { fn run(rt: Runtime) -> Result<()>; @@ -34,10 +34,12 @@ pub trait ImagApplication { macro_rules! simple_imag_application_binary { ($application_library:ident, $application_implementor:ident) => { extern crate libimagerror; - extern crate failure; + extern crate anyhow; extern crate $application_library; - use failure::{Error, Fallible as Result, ResultExt}; + use anyhow::Error; + use anyhow::Result; + use anyhow::Context; fn main() { use libimagerror::trace::MapErrTrace; diff --git a/lib/core/libimagrt/src/configuration.rs b/lib/core/libimagrt/src/configuration.rs index 000c20ba..7de02eb3 100644 --- a/lib/core/libimagrt/src/configuration.rs +++ b/lib/core/libimagrt/src/configuration.rs @@ -21,12 +21,12 @@ use std::path::PathBuf; use toml::Value; use clap::App; -use failure::ResultExt; -use failure::Fallible as Result; -use failure::Error; -use failure::err_msg; +use anyhow::Context; +use anyhow::Result; +use anyhow::Error; -use libimagerror::errors::ErrorMsg as EM; + +use libimagerror::errors::Error as EM; /// Get a new configuration object. /// @@ -119,18 +119,17 @@ pub fn override_config(val: &mut Value, v: Vec<String>) -> Result<()> { None })) .map(|(k, v)| { - let value = val.read_mut(&k) - .context(EM::TomlQueryError)? - .ok_or_else(|| err_msg("No config value there, cannot override."))?; + let value = val.read_mut(&k)? + .ok_or_else(|| anyhow!("No config value there, cannot override."))?; let new_value = into_value(value, v) - .ok_or_else(|| err_msg("Config override type not matching"))?; + .ok_or_else(|| anyhow!("Config override type not matching"))?; info!("Successfully overridden: {} = {}", k, new_value); *value = new_value; Ok(()) }) - .map(|elem: Result<()>| elem.context(err_msg("Config override error")).map_err(Error::from)) + .map(|elem: Result<()>| elem.context(anyhow!("Config override error")).map_err(Error::from)) .collect::<Result<()>>() } diff --git a/lib/core/libimagrt/src/iter.rs b/lib/core/libimagrt/src/iter.rs index 519d6c65..153aa794 100644 --- a/lib/core/libimagrt/src/iter.rs +++ b/lib/core/libimagrt/src/iter.rs @@ -23,8 +23,8 @@ mod reporting { use libimagstore::store::Entry; use libimagstore::storeid::StoreId; - use failure::Fallible as Result; - use failure::Error; + use anyhow::Result; + use anyhow::Error; use runtime::Runtime; diff --git a/lib/core/libimagrt/src/lib.rs b/lib/core/libimagrt/src/lib.rs index f7c9f579..c36e2d01 100644 --- a/lib/core/libimagrt/src/lib.rs +++ b/lib/core/libimagrt/src/lib.rs @@ -42,7 +42,7 @@ extern crate itertools; extern crate ansi_term; extern crate handlebars; extern crate serde; -#[macro_use] extern crate failure; +#[macro_use] extern crate anyhow; #[macro_use] extern crate toml_query; extern crate clap; 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) } diff --git a/lib/core/libimagrt/src/runtime.rs b/lib/core/libimagrt/src/runtime.rs index c29a2846..90ad0920 100644 --- a/lib/core/libimagrt/src/runtime.rs +++ b/lib/core/libimagrt/src/runtime.rs @@ -31,16 +31,15 @@ use toml::Value; use toml_query::read::TomlValueReadExt; use clap::{Arg, ArgMatches}; -use failure::ResultExt; -use failure::Fallible as Result; -use failure::Error; -use failure::err_msg; +use anyhow::Context; +use anyhow::Result; +use anyhow::Error; + use crate::configuration::{fetch_config, override_config, InternalConfiguration}; use crate::logger::ImagLogger; use crate::io::OutputProxy; -use libimagerror::errors::ErrorMsg as EM; use libimagerror::trace::*; use libimagstore::store::Store; use libimagstore::storeid::StoreId; @@ -85,10 +84,10 @@ impl<'a> Runtime<'a> { let config = match fetch_config(&configpath)? { None => { - return Err(err_msg("No configuration file found")) - .context(err_msg("Maybe try to use 'imag-init' to initialize imag?")) - .context(err_msg("Continuing without configuration file")) - .context(err_msg("Cannot instantiate runtime")) + return Err(anyhow!("No configuration file found")) + .context(anyhow!("Maybe try to use 'imag-init' to initialize imag?")) + .context(anyhow!("Continuing without configuration file")) + .context(anyhow!("Cannot instantiate runtime")) .map_err(Error::from); }, Some(mut config) => { @@ -160,7 +159,7 @@ impl<'a> Runtime<'a> { input_data, output_data, }) - .context(err_msg("Cannot instantiate runtime")) + .context(anyhow!("Cannot instantiate runtime")) .map_err(Error::from) } @@ -389,15 +388,15 @@ impl<'a> Runtime<'a> { .map(String::from) .ok_or_else(|| { self.config() - .ok_or_else(|| err_msg("No Configuration!")) + .ok_or_else(|| anyhow!("No Configuration!")) .and_then(|v| match v.read("rt.editor")? { Some(&Value::String(ref s)) => Ok(Some(s.clone())), - Some(_) => Err(err_msg("Type error at 'rt.editor', expected 'String'")), + Some(_) => Err(anyhow!("Type error at 'rt.editor', expected 'String'")), None => Ok(None), }) }) .or_else(|_| env::var("EDITOR")) - .map_err(|_| Error::from(EM::IO)) + .map_err(Error::from) .and_then(|s| { debug!("Editing with '{}'", s); let mut split = s.split_whitespace(); @@ -407,7 +406,7 @@ impl<'a> Runtime<'a> { } let mut c = Command::new(command.unwrap()); // secured above c.args(split); - c.stdin(::std::fs::File::open("/dev/tty").context(EM::IO)?); + c.stdin(::std::fs::File::open("/dev/tty")?); c.stderr(::std::process::Stdio::inherit()); Ok(Some(c)) }) @@ -500,7 +499,7 @@ impl<'a> Runtime<'a> { let rtp_str = self.rtp() .to_str() .map(String::from) - .ok_or_else(|| Error::from(EM::IO))?; + .ok_or_else(|| anyhow!("UTF8 Error: Runtimepath is not valid UTF8"))?; let command = format!("{}-{}", command.as_ref(), subcommand.as_ref()); @@ -531,7 +530,6 @@ impl<'a> Runtime<'a> { }, _ => e, }) - .context(EM::IO) .map_err(Error::from) } @@ -568,7 +566,7 @@ impl<'a> Runtime<'a> { return if e.kind() == std::io::ErrorKind::BrokenPipe { Ok(false) } else { - Err(failure::Error::from(e)) + Err(Error::from(e)) } } } @@ -675,7 +673,7 @@ pub fn get_rtp_match<'a>(matches: &ArgMatches<'a>) -> Result<PathBuf> { match env::var("IMAG_RTP").map(PathBuf::from) { Ok(p) => return Ok(p), Err(env::VarError::NotUnicode(_)) => { - return Err(err_msg("Environment variable 'IMAG_RTP' does not contain valid Unicode")) + return Err(anyhow!("Environment variable 'IMAG_RTP' does not contain valid Unicode")) }, Err(env::VarError::NotPresent) => { /* passthrough */ } } @@ -685,10 +683,10 @@ pub fn get_rtp_match<'a>(matches: &ArgMatches<'a>) -> Result<PathBuf> { .map(|mut p| { p.push(".imag"); p }) .map_err(|e| match e { env::VarError::NotUnicode(_) => { - err_msg("Environment variable 'HOME' does not contain valid Unicode") + anyhow!("Environment variable 'HOME' does not contain valid Unicode") }, env::VarError::NotPresent => { - err_msg("You seem to be $HOME-less. Please get a $HOME before using this \ + anyhow!("You seem to be $HOME-less. Please get a $HOME before using this \ software. We are sorry for you and hope you have some \ accommodation anyways.") } |