summaryrefslogtreecommitdiffstats
path: root/lib/core/libimagrt/src/runtime.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/core/libimagrt/src/runtime.rs')
-rw-r--r--lib/core/libimagrt/src/runtime.rs38
1 files changed, 18 insertions, 20 deletions
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.")
}