summaryrefslogtreecommitdiffstats
path: root/lib/core
diff options
context:
space:
mode:
Diffstat (limited to 'lib/core')
-rw-r--r--lib/core/libimagerror/Cargo.toml4
-rw-r--r--lib/core/libimagerror/src/lib.rs4
-rw-r--r--lib/core/libimagerror/src/trace.rs2
-rw-r--r--lib/core/libimagrt/Cargo.toml4
-rw-r--r--lib/core/libimagrt/src/application.rs8
-rw-r--r--lib/core/libimagrt/src/configuration.rs19
-rw-r--r--lib/core/libimagrt/src/iter.rs4
-rw-r--r--lib/core/libimagrt/src/lib.rs2
-rw-r--r--lib/core/libimagrt/src/logger.rs49
-rw-r--r--lib/core/libimagrt/src/runtime.rs38
-rw-r--r--lib/core/libimagstore/Cargo.toml4
-rw-r--r--lib/core/libimagstore/src/configuration.rs13
-rw-r--r--lib/core/libimagstore/src/file_abstraction/fs.rs45
-rw-r--r--lib/core/libimagstore/src/file_abstraction/inmemory.rs10
-rw-r--r--lib/core/libimagstore/src/file_abstraction/iter.rs2
-rw-r--r--lib/core/libimagstore/src/file_abstraction/mod.rs2
-rw-r--r--lib/core/libimagstore/src/iter.rs4
-rw-r--r--lib/core/libimagstore/src/lib.rs2
-rw-r--r--lib/core/libimagstore/src/store.rs134
-rw-r--r--lib/core/libimagstore/src/storeid.rs18
-rw-r--r--lib/core/libimagstore/src/util.rs13
21 files changed, 170 insertions, 211 deletions
diff --git a/lib/core/libimagerror/Cargo.toml b/lib/core/libimagerror/Cargo.toml
index 22b6eb8a..3b18a2f6 100644
--- a/lib/core/libimagerror/Cargo.toml
+++ b/lib/core/libimagerror/Cargo.toml
@@ -22,5 +22,5 @@ maintenance = { status = "actively-developed" }
[dependencies]
log = "0.4.6"
ansi_term = "0.12"
-failure = "0.1.5"
-failure_derive = "0.1.5"
+anyhow = "1"
+
diff --git a/lib/core/libimagerror/src/lib.rs b/lib/core/libimagerror/src/lib.rs
index 55d045a6..bacd831a 100644
--- a/lib/core/libimagerror/src/lib.rs
+++ b/lib/core/libimagerror/src/lib.rs
@@ -37,8 +37,8 @@
#[macro_use] extern crate log;
extern crate ansi_term;
-extern crate failure;
-#[macro_use] extern crate failure_derive;
+extern crate anyhow;
+
pub mod errors;
pub mod exit;
diff --git a/lib/core/libimagerror/src/trace.rs b/lib/core/libimagerror/src/trace.rs
index 1b192e44..f990f1b1 100644
--- a/lib/core/libimagerror/src/trace.rs
+++ b/lib/core/libimagerror/src/trace.rs
@@ -21,7 +21,7 @@ use std::process::exit;
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result as FmtResult;
-use failure::Error;
+use anyhow::Error;
use ansi_term::Colour::Red;
struct ImagTrace<'a, T: 'a + ?Sized>(&'a T);
diff --git a/lib/core/libimagrt/Cargo.toml b/lib/core/libimagrt/Cargo.toml
index 0a5f8841..50229e6c 100644
--- a/lib/core/libimagrt/Cargo.toml
+++ b/lib/core/libimagrt/Cargo.toml
@@ -26,8 +26,8 @@ xdg-basedir = "1.0.0"
itertools = "0.8.0"
ansi_term = "0.12"
atty = "0.2.11"
-failure = "0.1.5"
-failure_derive = "0.1.5"
+anyhow = "1"
+
serde_derive = "1.0.94"
serde = "1.0.94"
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.")
}
diff --git a/lib/core/libimagstore/Cargo.toml b/lib/core/libimagstore/Cargo.toml
index f14f7c1b..6357b183 100644
--- a/lib/core/libimagstore/Cargo.toml
+++ b/lib/core/libimagstore/Cargo.toml
@@ -29,8 +29,8 @@ walkdir = "2.2.8"
is-match = "0.1.0"
serde = "1.0.94"
serde_json = "1.0.39"
-toml-query = "0.9.2"
-failure = "0.1.5"
+toml-query = { git = "https://github.com/matthiasbeyer/toml-query", branch = "master" }
+anyhow = "1"
libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" }
libimagutil = { version = "0.10.0", path = "../../../lib/etc/libimagutil" }
diff --git a/lib/core/libimagstore/src/configuration.rs b/lib/core/libimagstore/src/configuration.rs
index 44c21a72..a2b2e1de 100644
--- a/lib/core/libimagstore/src/configuration.rs
+++ b/lib/core/libimagstore/src/configuration.rs
@@ -19,11 +19,9 @@
use toml::Value;
-use failure::Fallible as Result;
-use failure::ResultExt;
-use failure::Error;
-
-use libimagerror::errors::ErrorMsg as EM;
+use anyhow::Result;
+use anyhow::Context;
+use anyhow::Error;
/// Checks whether the store configuration has a key "implicit-create" which maps to a boolean
/// value. If that key is present, the boolean is returned, otherwise false is returned.
@@ -34,10 +32,9 @@ pub fn config_implicit_store_create_allowed(config: &Option<Value>) -> Result<bo
if let Some(ref t) = *config {
t.read_bool(key)
- .context(format_err!("Error reading header '{}' in configuration", key))
.map_err(Error::from)
- .context(EM::TomlQueryError)?
- .ok_or_else(|| format_err!("Config key missing: {}", key))
+ .context(anyhow!("Error reading header '{}' in configuration", key))?
+ .ok_or_else(|| anyhow!("Config key missing: {}", key))
} else {
Ok(false)
}
diff --git a/lib/core/libimagstore/src/file_abstraction/fs.rs b/lib/core/libimagstore/src/file_abstraction/fs.rs
index 5388a5c4..58350fca 100644
--- a/lib/core/libimagstore/src/file_abstraction/fs.rs
+++ b/lib/core/libimagstore/src/file_abstraction/fs.rs
@@ -22,8 +22,6 @@ use std::io::{Seek, SeekFrom, Read};
use std::path::{Path, PathBuf};
use std::sync::Arc;
-use libimagerror::errors::ErrorMsg as EM;
-
use super::FileAbstraction;
use super::FileAbstractionInstance;
use super::Drain;
@@ -33,9 +31,9 @@ use crate::file_abstraction::iter::PathIterator;
use crate::file_abstraction::iter::PathIterBuilder;
use walkdir::WalkDir;
-use failure::ResultExt;
-use failure::Fallible as Result;
-use failure::Error;
+use anyhow::Context;
+use anyhow::Result;
+use anyhow::Error;
#[derive(Debug)]
pub struct FSFileAbstractionInstance(PathBuf);
@@ -54,12 +52,11 @@ impl FileAbstractionInstance for FSFileAbstractionInstance {
Ok(Some(file)) => file,
};
- file.seek(SeekFrom::Start(0)).context(EM::FileNotSeeked)?;
+ file.seek(SeekFrom::Start(0))?;
let mut s = String::new();
file.read_to_string(&mut s)
- .context(EM::IO)
.map_err(Error::from)
.map(|_| s)
.and_then(|s: String| Entry::from_str(id, &s))
@@ -73,13 +70,12 @@ impl FileAbstractionInstance for FSFileAbstractionInstance {
use std::io::Write;
let buf = buf.to_str()?.into_bytes();
- let mut file = create_file(&self.0).context(EM::FileNotCreated)?;
+ let mut file = create_file(&self.0)?;
- file.seek(SeekFrom::Start(0)).context(EM::FileNotCreated)?;
- file.set_len(buf.len() as u64).context(EM::FileNotWritten)?;
- file.write_all(&buf)
- .context(EM::FileNotWritten)
- .map_err(Error::from)
+ file.seek(SeekFrom::Start(0))?;
+ file.set_len(buf.len() as u64)?;
+ file.write_all(&buf)?;
+ Ok(())
}
}
@@ -92,23 +88,18 @@ pub struct FSFileAbstraction {}
impl FileAbstraction for FSFileAbstraction {
fn remove_file(&self, path: &PathBuf) -> Result<()> {
- remove_file(path)
- .context(EM::FileNotRemoved)
- .map_err(Error::from)
+ remove_file(path).map_err(Error::from)
}
fn copy(&self, from: &PathBuf, to: &PathBuf) -> Result<()> {
- copy(from, to)
- .map(|_| ())
- .context(EM::FileNotCopied)
- .map_err(Error::from)
+ copy(from, to).map(|_| ()).map_err(Error::from)
}
fn rename(&self, from: &PathBuf, to: &PathBuf) -> Result<()> {
if let Some(p) = to.parent() {
if !p.exists() {
debug!("Creating: {:?}", p);
- create_dir_all(&p).context(EM::DirNotCreated)?;
+ create_dir_all(&p)?;
}
} else {
debug!("Failed to find parent. This looks like it will fail now");
@@ -116,16 +107,12 @@ impl FileAbstraction for FSFileAbstraction {
}
debug!("Renaming {:?} to {:?}", from, to);
- rename(from, to)
- .context(EM::FileNotRenamed)
- .map_err(Error::from)
+ rename(from, to).map_err(Error::from)
}
fn create_dir_all(&self, path: &PathBuf) -> Result<()> {
debug!("Creating: {:?}", path);
- create_dir_all(path)
- .context(EM::DirNotCreated)
- .map_err(Error::from)
+ create_dir_all(path).map_err(Error::from)
}
fn exists(&self, path: &PathBuf) -> Result<bool> {
@@ -183,7 +170,7 @@ impl PathIterBuilder for WalkDirPathIterBuilder {
.map(|r| {
trace!("Working in PathIterator with {:?}", r);
r.map(|e| PathBuf::from(e.path()))
- .context(format_err!("Error in Walkdir"))
+ .context(anyhow!("Error in Walkdir"))
.map_err(Error::from)
}))
}
@@ -194,7 +181,7 @@ impl PathIterBuilder for WalkDirPathIterBuilder {
debug!(" -> path : {:?}", self.basepath);
if !self.basepath.exists() {
- Err(format_err!("Does not exist: {}", self.basepath.display()))
+ Err(anyhow!("Does not exist: {}", self.basepath.display()))
} else {
Ok(())
}
diff --git a/lib/core/libimagstore/src/file_abstraction/inmemory.rs b/lib/core/libimagstore/src/file_abstraction/inmemory.rs
index 2deabcae..f6a0e289 100644
--- a/lib/core/libimagstore/src/file_abstraction/inmemory.rs
+++ b/lib/core/libimagstore/src/file_abstraction/inmemory.rs
@@ -24,11 +24,11 @@ use std::cell::RefCell;
use std::sync::Arc;
use std::ops::Deref;
-use libimagerror::errors::ErrorMsg as EM;
+use libimagerror::errors::Error as EM;
+
+use anyhow::Result;
+use anyhow::Error;
-use failure::Fallible as Result;
-use failure::Error;
-use failure::err_msg;
use super::FileAbstraction;
use super::FileAbstractionInstance;
@@ -140,7 +140,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
let a = backend.remove(from).ok_or_else(|| EM::FileNotFound)?;
let new_entry = {
let new_location = if to.starts_with("/") {
- let s = to.to_str().map(String::from).ok_or_else(|| err_msg("Failed to convert path to str"))?;
+ let s = to.to_str().map(String::from).ok_or_else(|| anyhow!("Failed to convert path to str"))?;
PathBuf::from(s.replace("/", ""))
} else {
to.to_path_buf()
diff --git a/lib/core/libimagstore/src/file_abstraction/iter.rs b/lib/core/libimagstore/src/file_abstraction/iter.rs
index 14649ac9..e24177b1 100644
--- a/lib/core/libimagstore/src/file_abstraction/iter.rs
+++ b/lib/core/libimagstore/src/file_abstraction/iter.rs
@@ -21,7 +21,7 @@ use std::path::PathBuf;
use std::sync::Arc;
use std::fmt::Debug;
-use failure::Fallible as Result;
+use anyhow::Result;
use crate::storeid::StoreIdWithBase;
use crate::file_abstraction::FileAbstraction;
diff --git a/lib/core/libimagstore/src/file_abstraction/mod.rs b/lib/core/libimagstore/src/file_abstraction/mod.rs
index f277e0cf..a46151d6 100644
--- a/lib/core/libimagstore/src/file_abstraction/mod.rs
+++ b/lib/core/libimagstore/src/file_abstraction/mod.rs
@@ -22,7 +22,7 @@ use std::fmt::Debug;
use std::collections::HashMap;
use std::sync::Arc;
-use failure::Fallible as Result;
+use anyhow::Result;
use crate::store::Entry;
use crate::storeid::StoreIdWithBase;
diff --git a/lib/core/libimagstore/src/iter.rs b/lib/core/libimagstore/src/iter.rs
index 060dc791..cd0b1ad2 100644
--- a/lib/core/libimagstore/src/iter.rs
+++ b/lib/core/libimagstore/src/iter.rs
@@ -31,7 +31,7 @@ macro_rules! mk_iterator_mod {
#[allow(unused_imports)]
use crate::store::FileLockEntry;
use crate::store::Store;
- use failure::Fallible as Result;
+ use anyhow::Result;
pub struct $itername<'a>(Box<dyn Iterator<Item = Result<StoreId>> + 'a>, &'a Store);
@@ -144,7 +144,7 @@ use self::get::StoreGetIterator;
use self::retrieve::StoreRetrieveIterator;
use crate::file_abstraction::iter::PathIterator;
use crate::store::Store;
-use failure::Fallible as Result;
+use anyhow::Result;
/// Iterator for iterating over all (or a subset of all) entries
///
diff --git a/lib/core/libimagstore/src/lib.rs b/lib/core/libimagstore/src/lib.rs
index 754647d0..a7a4be3d 100644
--- a/lib/core/libimagstore/src/lib.rs
+++ b/lib/core/libimagstore/src/lib.rs
@@ -46,7 +46,7 @@ extern crate semver;
extern crate walkdir;
#[macro_use] extern crate is_match;
extern crate serde_json;
-#[macro_use] extern crate failure;
+#[macro_use] extern crate anyhow;
extern crate toml_query;
extern crate libimagerror;
diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs
index e5748121..79eb5b3e 100644
--- a/lib/core/libimagstore/src/store.rs
+++ b/lib/core/libimagstore/src/store.rs
@@ -30,15 +30,15 @@ use std::fmt::Formatter;
use std::fmt::Debug;
use std::fmt::Error as FMTError;
-use libimagerror::errors::ErrorMsg as EM;
+use libimagerror::errors::Error as EM;
use toml::Value;
use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
-use failure::Fallible as Result;
-use failure::ResultExt;
-use failure::err_msg;
-use failure::Error;
+use anyhow::Result;
+use anyhow::Context;
+
+use anyhow::Error;
use crate::storeid::{IntoStoreId, StoreId};
use crate::iter::Entries;
@@ -70,9 +70,7 @@ impl StoreEntry {
#[cfg(feature = "fs-lock")]
{
- open_file(pb.clone())
- .and_then(|f| f.lock_exclusive())
- .with_context(|| EM::IO)?;
+ open_file(pb.clone()).and_then(|f| f.lock_exclusive())?;
}
Ok(StoreEntry {
@@ -96,7 +94,7 @@ impl StoreEntry {
None => Ok(Entry::new(self.id.clone()))
}
} else {
- Err(format_err!("EntryAlreadyBorrowed: {}", self.id))
+ Err(anyhow!("EntryAlreadyBorrowed: {}", self.id))
}
}
@@ -188,18 +186,15 @@ impl Store {
debug!("Building new Store object");
if !location.exists() {
if !config_implicit_store_create_allowed(store_config)? {
- return Err(format_err!("CreateStoreDirDenied"))
- .context(EM::FileError)
- .context(EM::IO)
- .map_err(Error::from)
+ return Err(anyhow!("CreateStoreDirDenied"));
}
backend
.create_dir_all(&location)
- .context(format_err!("StorePathCreate: {}", location.display()))?;
+ .context(anyhow!("StorePathCreate: {}", location.display()))?;
} else if location.is_file() {
debug!("Store path exists as file");
- return Err(format_err!("StorePathExists: {}", location.display()));
+ return Err(anyhow!("StorePathExists: {}", location.display()));
}
let store = Store {
@@ -222,8 +217,8 @@ impl Store {
self.entries
.read()
- .map_err(|_| Error::from(EM::LockError))
- .context(format_err!("Error while checking whether {} is borrowed", id))
+ .map_err(|_| EM::LockError)
+ .context(anyhow!("Error while checking whether {} is borrowed", id))
.map(|cache| cache.get(&id).map(|e| e.is_borrowed()).unwrap_or(false))
.map_err(Error::from)
}
@@ -243,20 +238,20 @@ impl Store {
if exists {
debug!("Entry exists: {:?}", id);
- return Err(format_err!("EntryAlreadyExists: {}", id));
+ return Err(anyhow!("EntryAlreadyExists: {}", id));
}
{
let mut hsmap = self
.entries
.write()
- .map_err(|_| Error::from(EM::LockError))
- .context(format_err!("CreateCallError: {}", id))?;
+ .map_err(|_| EM::LockError)
+ .context(anyhow!("CreateCallError: {}", id))?;
if hsmap.contains_key(&id) {
debug!("Cannot create, internal cache already contains: '{}'", id);
- return Err(format_err!("EntryAlreadyExists: {}", id))
- .context(format_err!("CreateCallError: {}", id))
+ return Err(anyhow!("EntryAlreadyExists: {}", id))
+ .context(anyhow!("CreateCallError: {}", id))
.map_err(Error::from)
}
hsmap.insert(id.clone(), {
@@ -288,7 +283,8 @@ impl Store {
let entry = self
.entries
.write()
- .map_err(|_| Error::from(EM::LockError))
+ .map_err(|_| EM::LockError)
+ .map_err(Error::from)
.and_then(|mut es| {
let new_se = StoreEntry::new(self.path().clone(), id.clone(), &self.backend)?;
let se = es.entry(id.clone()).or_insert(new_se);
@@ -296,7 +292,7 @@ impl Store {
se.s